COCOS2D API 之 CompositionAction


Actions: Composition

There are some actions that let you compose actions.

  • Sequence action
  • Spawn action
  • Repeat action
  • RepeatForever action

Sequence

TheCCSequenceaction is a list of actions. The actions are executed in the order that they are defined.

Example:

id action1 = [CCMoveTo actionWithDuration:2 position:ccp(100,100)];
id action2 = [CCMoveBy actionWithDuration:2  position: ccp(80,80)];
id action3 = [CCMoveBy actionWithDuration:2  position: ccp(0,80)];
[sprite runAction: [CCSequence actions:action1, action2, action3, nil]];

Theaction1will be executed first. Whenaction1finishes, thenaction2will be executed. And whenaction2finishes, only thenaction3will be executed.

*IMPORTANT:* The inner actions should have a non-infinite time (e.g.: You can't add aCCRepeatForeveraction in aCCSequenceaction).

Spawn

TheCCSpawnaction lets you run several actions at the same time. The duration of theCCSpawnaction will be the duration of the longest sub-action.

id action = [CCSpawn actions:
		[CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4],
		[CCRotateBy actionWithDuration: 2 angle: 720],
		nil];

[sprite runAction:action];

Repeat

TheCCRepeataction lets you repeat an action a limited number of times. Example:

id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)];
id action1 = [CCRepeat actionWithAction:
		[CCSequence actions: [CCPlace actionWithPosition:ccp(60,60)], a1, nil]
		times:3];
[sprite runAction:action1];

RepeatForever

TheCCRepeatForeveraction is a special action. Since it will repeat an action forever, its duration can't be measured.

Example:

id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)];
id action2 = [CCRepeatForever actionWithAction:
		[CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil]
	];
[sprite runAction:action2];

*IMPORTANT*:CCRepeatForeveris not a validCCIntervalAction. You can't use aCCRepeatForeverinside aCCSequenceaction.

长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn