Action of Cocos2d learning notes

Source: Internet
Author: User

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]):

 
 
  1. Move to-CCMoveTo
  2. Mobile-CCMoveBy
  3. Jump to-CCJumpTo to set the end point and the height and number of jumps.
  4. Jump-CCJumpBy: set the end position and the height and number of jumps.
  5. The beiser-CCBezierBy curve supports three times: P0-start point, P1-start point tangent direction, P2-end point tangent direction, and P3-end point.
  6. Zoom in to-CCScaleTo to set the zoom in factor, which is a floating point type.
  7. Zoom in-CCScaleBy
  8. Rotate to-CCRotateTo
  9. Rotate-CCRotateBy
  10. Flashing-CCBlink: set the number of flashes
  11. Tone changed to-CCTintTo
  12. Tone conversion-CCTintBy
  13. Darken to-CCFadeTo
  14. From non-Brightening-CCFadeIn
  15. 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.

 
 
  1. EaseIn is slow to fast.
  2. EaseOut from fast to slow
  3. EaseInOut starts from slow to fast and then from fast to slow.
  4. EaseSineIn
  5.  
  6. From slow to fast.
  7.  
  8. EaseSineOut from fast to slow
  9. EaseSineInOut starts from slow to fast and then from fast to slow.
  10. EaseExponentialIn is slow and fast.
  11. EaseExponentialOut is fast to slow.
  12. EaseExponentialInOut is slow from extremely fast to fast.
  13. 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.

 
 
  1. id acf = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)]; 

The corresponding function is:

 
 
  1. - (void) CallBack1 {  
  2. [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.

 
 
  1. id acf = [CallFuncN actionWithTarget:self selector:@selector(CallBack2:)]; 

Corresponding User-Defined Function: (here, we use this object directly)

 
 
  1. - (void) CallBack2:(id)sender {  
  2. [sender runAction:[CCTintBy actionWithDuration:1 red:255 green:0 blue:255]];   
  3. }  

With objects and data parameters-when using a custom function, the current object and a constant (or a pointer) are passed ).

 
 
  1. 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:

 
 
  1. -(void) CallBack3:(id)sender data:(void*)data {  
  2. [sender runAction:[CCTintBy actionWithDuration:(NSInteger)data red:255 green:0 blue:255]];   
  3. }  

Summary:Cocos2dStudy NotesActionI hope this article will help you!

Related Article

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.