Cocos2d-x Study Notes (3)-action

Source: Internet
Author: User

For a game, action is very important, good action can greatly improve the playability of the game, there is a category in the cocos2d-x engine, CCAction is the base class of the category class, an action is defined on a node (CCNode). It targets nodes and is divided into two types of instantaneous and delayed actions,
The implementation of an action mainly involves the following steps. Let's take the functions involved in the shanzhai fruit ninja as an example...
1. Create a node

Here is the function for creating Fruit. Fruit is a self-defined class. I create a random Fruit and set the location of the Fruit. Other codes are not understood for the time being. Www.2cto.com
2. Define actions

I have defined two curve motion modes for fruit, which are commonly used in-x. One is CCJumpTo, the other is CCBezierTo is the besell curve, and the other CCRotateTo is to rotate nodes, the use of the besell curve is important. You can check the relevant information to master it.
3. Execution of actions

Generally, you have several actions to execute, so it is very important to control the execution sequence of the actions, whether to execute them at the same time or one by one, CCFiniteTimeAction is used to define the actions to be executed within the specified time. The CCSequence action sequence is used to place the actions to be executed. It is difficult to control the execution sequence of the actions at the beginning.
(1) If you use this method to execute an action, the action is executed at the same time. actions is similar to cocos2d.

(2) If you use this method to execute an action, the action is executed in sequence, and the CCDelayTime is a function of the delay time.

Generally, a game Performs related operations (Message mechanisms) after calling an action. For example, you can navigate to another page or call the relevant callback function, which can be defined in CCFiniteTimeAciton, how to add it to the action queue so that it can be executed after the action is completed, such

Here I use CCCallFuncN to define an action to call the removefruit callback function. CCCallFuncN is designed for a Node, and "N" means Node, if it is not for a node, you can use CCCallFunc to define it. It also provides a very convenient interface, that is, reverse, to execute reactionary actions. You can use actionMoveDown-> reverse ().
Author: John_cdy

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.