Cocos2d-basic concepts (2)-composition actions complex actions

Source: Internet
Author: User

Actions: composition Complex Action

There are some actions that let you compose actions.

    • Sequence action
    • Spawn action
    • Repeat action
    • Repeatforever action
Sequence

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

Example:

 IDAction1 = [MoveTo Actionwithduration:2 Position:CCP(100,100)]; 

id Action2 = [ moveBy actionwithduration : 2 position : CCP ( 80 , 80 )];

IDAction3 = [MoveBy Actionwithduration:2Position:CCP(0,80)];

[SpriteRunaction:[Sequence Actions: Action1, Action2, action3,Nil];

TheAction1Will be executed first. WhenAction1Finishes, thenAction2Will be executed. And whenAction2Finishes, only thenAction3Will be executed.

* Important: * The inner actions showould have a non infinity time (eg: You can't addRepeatforeverAction inSequenceAction ).

 

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.

IDAction = [Spawn Actions:

[ jumpby actionwithduration : 2 position : CCP ( 300 , 0 ) height : 50 jumps : 4 ],

[Rotateby Actionwithduration:2 Angle:720],Nil];

[SpriteRunaction: Action];

Repeat already exists.

This repeated action allows you to repeat an action for a limited number of times. Example:

IDA1 = [MoveBy Actionwithduration:1 Position:CCP(150,0)];

IDAction1 = [Repeat Actionwithaction:

[Sequence Actions:[Place Actionwithposition:CCP(60,60)], A1,Nil]Times:3];

[SpriteRunaction: Action1];

Repeatforever always repeats

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

Example:

IDA1 = [MoveBy Actionwithduration:1 Position:CCP(150,0)];

IDAction2 = [Repeatforever Actionwithaction:

[Sequence Actions: [[A1Copy]Autorelease], [A1Reverse],Nil];

[SpriteRunaction: Action2];

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

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.