Cocos2d-android (04) 执行多个动作

先后、同时执行多个动作及动作序列执行结束后的事件

 1 import org.cocos2d.actions.instant.CCCallFunc;
 2 import org.cocos2d.actions.interval.CCMoveTo;
 3 import org.cocos2d.actions.interval.CCRotateTo;
 4 import org.cocos2d.actions.interval.CCScaleTo;
 5 import org.cocos2d.actions.interval.CCSequence;
 6 import org.cocos2d.actions.interval.CCSpawn;
 7 import org.cocos2d.layers.CCLayer;
 8 import org.cocos2d.nodes.CCSprite;
 9 import org.cocos2d.types.CGPoint;
10 
11 public class GameLayer extends CCLayer {
12 
13     private CCSprite sprite;
14 
15     public GameLayer() {
16         sprite = CCSprite.sprite("player.png");
17         this.addChild(sprite);
18 
19         CGPoint startPoint = CGPoint.ccp(200, 200);
20         sprite.setPosition(startPoint);
21         CGPoint targetPoint = CGPoint.ccp(600, 600);
22 
23         CCMoveTo moveTo = CCMoveTo.action(3, targetPoint);
24         CCRotateTo rotateTo = CCRotateTo.action(3, 270);
25         CCScaleTo scaleTo = CCScaleTo.action(3, 3);
26 
27         // 多个动作先后执行
28         CCSequence sequence = CCSequence.actions(moveTo, rotateTo, scaleTo);
29         // 多个动作同时执行
30         CCSpawn spawn = CCSpawn.actions(moveTo, rotateTo, scaleTo);
31         //执行当前对象中的某个方法
32         CCCallFunc callFunc = CCCallFunc.action(this, "onActionFinished");
33         CCSequence sequence1 = CCSequence.actions(moveTo, callFunc);
34 
35         sprite.runAction(sequence1);
36     }
37 
38     public void onActionFinished(Object sender) {
39         System.out.println("onActionFinished");
40     }
41 }

Cocos2d-android (04) 执行多个动作,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。