Action is the logical processing of nodes, such as moving, rotating, scaling, changing color, jumping, turning, and transparency of nodes.
How to Use Action on a Node
1. Define Action object
For example, auto act = MoveTo: create (Point (30,0), 1 );
2. Run runAction on Node
Auto sp = Sprite: create ("npc.png ");
Sp-> runAction (act );
In this way, the Node sp is moved to the coordinates of 30, 0, and completed in 1 second.
Of course, you can also use ActionManager to let a Node execute an action.
Auto director = Director: getInstance (); // 1 get the director object
Auto manager = director-> getActionManager (); // 2. Obtain the Action manager, which is also a singleton.
Void addAction (Action * action, Node * target, bool paused); // 3. Use this method
You can use
I. Combination of Sequence and Swap to implement Action
Auto action2 = Sequence: create (
ScaleBy: create (2, 2 ),
FadeOut: create (2 ),
CallFunc: create (std: bind (& ActionCallFunction: callback2, this, _ tamara )),
NULL );
Auto action = Spawn: create (
JumpBy: create (2, Point (300,0), 50, 4 ),
RotateBy: create (2,720 ),
NULL );
_ Grossini-> runAction (action );
2. RepeatForever
Auto repeat = RepeatForever: create (RotateBy: create (1.0f, 360 ));
Sender-> runAction (repeat );
3. CallFunc can be used to call a function (also an Action, which can be combined with Sequence to process the callback after an Action is completed)
CallFunc: create (std: bind (& ActionCallFunction: callback2, this, _ tamara ));
Here is Lambda. For more information, see my video.
4. You can use reverse to find the inverse of an Action.
Auto jump = JumpBy: create (2, Point (, 0), 50, 4 );
Auto action = Sequence: create (jump, jump-> reverse (), NULL );
_ Grossini-> runAction (action );
5. animation actions can be implemented through Animate (this is the focus and will be detailed later)
For the basic Action, you can view the TestCpp source code. The next section describes how to read the TestCpp source code.