In Cocos2d Study NotesActionThis is what I want to introduce. Thanks to ZhiyiCocos2dTutorials. Some important points are recorded when you read the tutorials for reference at any time. Let's take a look at the article.ActionRelated content.
1. Basic actions
Basic actions provided by Cocos2d: instantaneous actions, delayed actions, and operation speed.
Instantaneous action: an action that is completed immediately without time. The common base class of an instantaneous action is InstantAction.
Cocos2d provides the following instantaneous actions:
Placement-Place
The effect is similar to node. Position = ccp (x, y ). It is implemented as an action to form a continuous action with other actions.
Hide-Hide
The effect is similar to [node setVisible: NO]. It is implemented as a sequence to form a continuous action with other actions.
Show
The effect is similar to [node setVisible: YES]. It is implemented as an action to form a continuous action with other actions.
Visible switch-ToggleVisibility
2. delayed action
A delayed action takes some time to complete. Therefore, actionWithDuration is the first parameter when a delayed action is executed. The common base class of the delayed action is CCIntervalAction (including the combined response class ).
Cocos2d provides the following naming rules for instantaneous action functions: XxxxTo: means moving to the specified position, XxxxBy: means moving to the position according to the specified x, y increment. [X and y can be negative values]):
- Move to-CCMoveTo
- Mobile-CCMoveBy
- Jump to-CCJumpTo to set the end point and the height and number of jumps.
- Jump-CCJumpBy: set the end position and the height and number of jumps.
- The beiser-CCBezierBy curve supports three times: P0-start point, P1-start point tangent direction, P2-end point tangent direction, and P3-end point.
- Zoom in to-CCScaleTo to set the zoom in factor, which is a floating point type.
- Zoom in-CCScaleBy
- Rotate to-CCRotateTo
- Rotate-CCRotateBy
- Flashing-CCBlink: set the number of flashes
- Tone changed to-CCTintTo
- Tone conversion-CCTintBy
- Darken to-CCFadeTo
- From non-Brightening-CCFadeIn
- From bright to non-CCFadeOut
3. Combined Action
Combine the above basic actions in a certain order to form a coherent set of actions. Combined Actions include the following types:
Sequence-CCSequence
Sequence is very simple to use. This class is also derived from CCIntervalAction and can be executed by CocosNode objects. This class is used to arrange several actions in line order and then execute them one by one in order.
Synchronization-Spawn
The use of Spawn is very simple. This class is also derived from IntervalAction and can be executed by CocosNode objects. This class is used to concurrently execute several actions, but all actions must be executed simultaneously. For example, mobile flip, color change, and size change.
Note that the final completion time of synchronous execution is determined by the time spent in the basic action.
Repeate
A limited number of repeated actions. This class is also derived from IntervalAction and can be executed by CocosNode objects.
ReverseAction-Reverse
Reactionary action refers to reverse (reverse) execution of an action, supporting the reactionary action sequence for the action sequence. Reactionary action is not a special class, but an interface introduced by CCFiniteAction. Not all classes support reactionary actions. XxxxTo classes generally do not support reactionary actions. XxxxBy classes generally support reactionary actions.
Animation-Animation
Animation allows the genie to continuously execute an image to form a simulated motion effect: the genie state during walking and the State during fighting.
Unlimited RepeatForever
RepeatForever is fromActionClass is directly derived, so it cannot participate in sequence and synchronization, and it cannot be executed in reverse direction. This class is used to execute an action or action sequence indefinitely until it is stopped.
4. Speed Change
The basic and composite actions change the movements and animation effects of the genie, but the speed of such changes remains unchanged, through the CCEaseAction class and the CCSpped class, we can easily modify the speed at which the wizard executes the Failover task: From fast to slow or from slow to fast.
- EaseIn is slow to fast.
- EaseOut from fast to slow
- EaseInOut starts from slow to fast and then from fast to slow.
- EaseSineIn
-
- From slow to fast.
-
- EaseSineOut from fast to slow
- EaseSineInOut starts from slow to fast and then from fast to slow.
- EaseExponentialIn is slow and fast.
- EaseExponentialOut is fast to slow.
- EaseExponentialInOut is slow from extremely fast to fast.
- Speed: manually set the Speed. You can also use SetSpeed to continuously adjust the Speed.
5. Scaling
Delayed action-Delay, for example, adding a time interval to the action sequence
Function call
Function
Call a function in the middle or end of the action sequence to execute any task that needs to be executed: Action, status modification, etc.
- id acf = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)];
The corresponding function is:
- - (void) CallBack1 {
- [sprite runAction:[CCTintBy actionWithDuration:0.5 red:255 green:0 blue:255]]; }
With object parameters -- the current object is passed when a user-defined function is called.
- id acf = [CallFuncN actionWithTarget:self selector:@selector(CallBack2:)];
Corresponding User-Defined Function: (here, we use this object directly)
- - (void) CallBack2:(id)sender {
- [sender runAction:[CCTintBy actionWithDuration:1 red:255 green:0 blue:255]];
- }
With objects and data parameters-when using a custom function, the current object and a constant (or a pointer) are passed ).
- id acf = [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2];
For the corresponding user-defined functions, we use the passed objects and data:
- -(void) CallBack3:(id)sender data:(void*)data {
- [sender runAction:[CCTintBy actionWithDuration:(NSInteger)data red:255 green:0 blue:255]];
- }
Summary:Cocos2dStudy NotesActionI hope this article will help you!