On an article we realized the Sprite animation, but the character moved up, the position is still in the center, how can this work, unless he is playing space step, step two step by step two step by step like Minion like Devil's pace ... Friction friction on this smooth ground friction
We open the installation road: \quick-3.3rc1\docs\api The following transition.html, this time we use the function of the document introduced into the wizard to perform the action
We'll let the Elves go to the right.
Let's look at the function of Transition.exectue (target, action, args), in the middle is the action we created.
function Mainscene:ctor () display.addspriteframes ("Lqfrolewalk.plist", "Lqfrolewalk.png") Local sprite = Display.newsprite ("#lqfRightStop. png") sprite:align (display. center,20,display.cy) sprite:addto (self) sprite:setscale (2) Local frames = Display.newframes ("Lqfrightwalk%d.png", ) Local animation = Display.newanimation (FRAMES,0.5/2) display.setanimationcache ("Lqfrightwalk", animation) Sprite :p Layanimationforever (Display.getanimationcache ("Lqfrightwalk")) Transition.execute (SPRITE,CC. Moveto:create (3, CC.P (display.width-20,display.cy)), {delay = 0.23,oncomplete = function () print ("Running End") Sprite: Stopallactions () Sprite:setspriteframe (Display.newspriteframe ("Lqfrightstop.png")) end}) end
Above is the code of our previous article, we will focus on the 20,display.cy coordinates where, see Transition.execute in the middle of a parameter, the COCOS2DX LUA native function, is moved within 3s to ( DISPLAY.WIDTH-20,DISPLAY.CY) This position, the last parameter is a table, which has various parameters, delay is how long it takes to perform the current action, the key is that this member of the OnComplete, this member has stored a function, Used to handle finishing work after an action is performed, such as cleaning up the memory of the sprite that performed the action
Of course, I didn't clean up the genie, just after the action, let the genie stop running and change the sprite frame to a stop state.
Let's see how the code works.
If I want to perform multiple actions, how do I write it?
I want to perform other actions after the action is done
This will use the Transition.sequence () function, the direct code, the following explanation
function Mainscene:ctor () display.addspriteframes ("Lqfrolewalk.plist", "Lqfrolewalk.png") Local sprite = Display.newsprite ("#lqfRightStop. png") sprite:align (display. center,20,display.cy) sprite:addto (self) sprite:setscale (2) Local frames = Display.newframes ("Lqfrightwalk%d.png", ) Local animation = Display.newanimation (FRAMES,0.5/2) display.setanimationcache ("Lqfrightwalk", animation) Sprite :p Layanimationforever (Display.getanimationcache ("Lqfrightwalk")) Local sequenceaction = Transition.sequence ({cc. Moveto:create (1, CC.P (display.cx,display.cy)), CC. Rotateby:create (2,360), CC. Jumpto:create (1,CC.P (display.cx+100,display.cy), 50,2), CC. Moveto:create (1, CC.P (display.width-20,display.cy))}) Transition.execute (Sprite,sequenceaction,{delay = 0.23, OnComplete = function () print ("Running End") sprite:stopallactions () Sprite:setspriteframe (Display.newspriteframe (" Lqfrightstop.png ")) end}) end
We use Transition.sequence to create a series of actions, and then to Transition.execute execution, you will ask, why sometimes with cc primitive function, sometimes with transition series functions, such as MOVETO,CC native has a, transition inside There is also a, this makes people very confused, we directly into the Transition.lua to see the source code
function Transition.moveto (target, args) assert (not Tolua.isnull (target), "Transition.moveto () – Target is not CC. Node ") local tx, Ty = target:getposition () local x = args.x or tx local y = args.y or ty Local action = CC . Moveto:create (Args.time, CC.P (x, y)) return Transition.execute (target, action, args) end
See, he finally called the Transition.execute function, directly to help you perform the creation of the action, rather than let you create a good, and then call the Transition.execute function execution.
Sequential execution of the action is completed, but we sometimes want to, at the same time, the action, the game inside the characters jump, flip, this is not sequence can be completed, there are ways, but transition did not give us a package, we directly call the native COCOS2DX The LUA code is on the line, creating the action, and then executing it with Transition.execute.
Local sequenceaction = cc. Spawn:create ({cc. Rotateby:create (3,360), CC. Jumpto:create (3,CC.P (display.width-20,display.cy), 50,5),}) Transition.execute (Sprite,sequenceaction,{delay = 0.23 , OnComplete = function () print ("Running End") sprite:stopallactions () Sprite:setspriteframe (Display.newspriteframe (" Lqfrightstop.png ")) end})
See
Well, the action is basically complete. Tired bird.
Quick Cocos2dx-lua (V3.3R1) Learning Notes (vii)----Let sprites perform different actions