Cocos2d-x 3.0 final Terminator series tutorial 10-Action in a drawing Node

Source: Internet
Author: User

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.


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.