To move an object from the outside of the screen to the specified position on the screen,
Code:
1--Add animations,2--1. Create the first picture of the mushroom,3--2. Set the picture location,4--3. Add a picture to the scene,5Self.player = Display.newsprite ("#binggu_01. png" )6Self.player:align (display. CENTER,-self.player:getContentSize (). width, display.cy)7 self.player:addTo (self)8 9--Create an array of 4 image frame objects that contain flying1.png to Flying4.pngTenLocal frames = Display.newframes ("Binggu_0%d.png",1,7 ) One A--creates an animated Animation object with an array that contains image frames -Local animation = Display.newanimation (frames,0.3/4 ) - the--loops the animation on the display object and returns the action animation action object - Transition.playanimationforever (Self.player, animation) - ---Create an action, an action that executes sequentially +--1. Move to the middle of the screen ---2the position coordinates to which the print is moved +Local action =Transition.sequence ( A { atCc. Moveto:create (5, CC.P (display.cx, display.cy)), - cc. Callfunc:create ( - function () -Print"----player:getposition ()----", Self.player:getPosition ()) - end) - } in ) ---Let the player perform this action toSelf.player:runAction (Action)
In this function,
We first get the animation we need from the animation cache,
Then let the self.player protagonist play the animation continuously;
It then creates an action to let Self.player execute.
The Transition.sequence () method can create a sequence action sequence object,
An object of type Sequence enables a Node sequence to perform a batch of actions,
This creates a first-MoveTo action,
The object that executes the Callfunc action after the MoveTo action is executed.
In layman's words, it is the function of moving to the screen (display.cx, display.cy) point, in the Call function () method in the print ().
MoveTo action should not be difficult to understand, because the fourth chapter we also talked about its brother Moveby.
The Moveby action enables the node to be uniform motion from the current coordinate point to a position relative to a certain vector.
MoveTo, in turn, enables the node to be uniform motion from the current coordinate point to the specified position coordinates.
Their moving position is relative, one is absolute, and this is the main difference between all the actions in the Cocos engine with the To,by suffix.
The Callfunc action is a function callback action that is used to invoke the method in the action,
Personally feel it is very necessary to exist in an action.
Because many times, when certain actions are completed, some data or logical processing is required
(for example, an enemy needs to remove and clean up memory after playing the death animation),
At this point, the use of function callback action Callfunc is no better.
Results:
quick-cocos2d-x3.3 Study (11)---------to move objects from the outside of the screen to the specified position on the screen