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