Composition of Actions in Cocos2D for iPhone game development

Source: Internet
Author: User

IPhone gamesDevelopmentCocos2DMediumActionsIs the content to be introduced in this article, mainly to learnActions. AsIphone gamesDuring development, you should not miss any useful article. Let's talk about it later. Let's take a look at the details.

Sequence

Ordered actions allow you to create a series of actions that will be executed in order.

 
 
  1.  id action1 = [MoveTo actionWithDuration:2 position:ccp(100,100)];  
  2. id action2 = [MoveBy actionWithDuration:2  position: ccp(80,80)];  
  3. id action3 = [MoveBy actionWithDuration:2  position: ccp(0,80)];  
  4. [sprite runAction: [Sequence actions:action1, action2, action3, nil]]; 

Action1 will be executed first. When action1 is executed, action2 will be executed. When action2 ends, it is action3.

Note: This action cannot be an infinite time. For example, you cannot add an action that repeats to the action sequence forever.

Spawn concurrency

This action allows you to run multiple actions at the same time. The duration of this operation is the longest time of the sub-action.

 
 
  1.  id action = [Spawn actions:  
  2. [JumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4],  
  3. [RotateBy actionWithDuration: 2 angle: 720],nil];  
  4. [sprite runAction:action]; 

Repeat already exists.

This repeated Action allows you to repeat an Action for a limited number of times.

 
 
  1.  id a1 = [MoveBy actionWithDuration:1 position:ccp(150,0)];  
  2. id action1 = [Repeat actionWithAction:  
  3. [Sequence actions: [Place actionWithPosition:ccp(60,60)], a1, nil]times:3];  
  4. [sprite runAction:action1]; 

RepeatForever always repeats

Repeating this action forever is a special action that will continue. Because its time cannot be measured.

 
 
  1.  id a1 = [MoveBy actionWithDuration:1 position:ccp(150,0)];  
  2. id action2 = [RepeatForever actionWithAction:  
  3. [Sequence actions: [[a1 copy] autorelease], [a1 reverse], nil] ];  
  4. [sprite runAction:action2]; 

Note: This action that is always repeated is not a valid IntervalAction and cannot be placed in a sequence action.

Summary: AboutIPhone gamesDevelopmentCocos2DMediumActionsI 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.