Quick Cocos2dx-lua (V3.3R1) Learning notes (vi)----Let the Elves move, use sequence frame animation

Source: Internet
Author: User

Light has the spirit is too rigid, the game must have a different animation, is the character moving around, a static figure can be sent to the game quality requirements more and more high players? So we're going to let the elves move.

Quick provides a function that uses sequence frame animation, which we can use directly.

The large image is now loaded into the cache and then extracted for use.

The main is the Display,newframes parameter, this kind of String.Format taste

@function [parent= #display] newframes--@param string pattern Strings--@param integer begin index--@param integer length --@param Whether Boolean isreversed is a descending index--@return table#table ret (return value:table)  image frame Array

  

Be aware of your image name format when using it, such as your thing sprite001.png--sprite009.png, parameter is ("Srite%00d.png", 1,9)

function Mainscene:ctor () display.addspriteframes ("Lqfrolewalk.plist", "Lqfrolewalk.png") Local sprite = Display.newsprite ("#lqfDownStop. png") sprite:align (display. center,display.cx,display.cy) sprite:addto (self) sprite:setscale (2) Local frames = Display.newframes ("lqfdownwalk% D.png ",") Local animation = Display.newanimation (FRAMES,0.5/2)     --0.5s inside play 2 frames Sprite:playanimationforever ( Animation) End

  

We see two pictures, the character foot changes (in fact, I was too lazy to intercept the dynamic map, haha haha, forgive my laziness)

But we can not use the time to create the animation bar, we may also before entering the scene, the required animation new, stored in the cache, when used to call the name directly

See the code below

function Mainscene:ctor () display.addspriteframes ("Lqfrolewalk.plist", "Lqfrolewalk.png") Local sprite = Display.newsprite ("#lqfDownStop. png") sprite:align (display. center,display.cx,display.cy) sprite:addto (self) sprite:setscale (2) Local frames = Display.newframes ("lqfdownwalk% D.png ",") Local animation = Display.newanimation (FRAMES,0.5/2) display.setanimationcache ("Lqfdownwalk", animation) Sprite:playanimationforever (Display.getanimationcache ("Lqfdownwalk")) end

  

We do this by storing an animation in the cache and then fetching it when it is needed.

Well, this is short, but can be rotated, oh, not yet rotated, the next one is writing! O (∩_∩) o

Quick Cocos2dx-lua (V3.3R1) Learning notes (vi)----Let the Elves move, use sequence frame animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.