CCMoveTo* move = [CCMoveTo actionWithDuration:3 postion:CGPointMake(100,200)];//(100,200)へ3秒以内に移動 [myNode runAction:move];
アクションにはインスタンスアクションとインターバルアクションの2種類がある。インスタンスアクションは、基本的にはvisibleやflipXのようなノードプロパティを設定するのと同じ。インターバルアクションは上の移動のように一定時間にわたって実行される。
アクションは終わると自動的にノードから削除され、メモリから解放される。
アクションを繰り返す
CCRotateBy* rotateBy = [CCRotateBy actionWithDuration:2 angle:360]; CCRepeateForever* repeat = [CCRepeatForever actionWithAction:rotateBy]; [myNode runAction:repeat];//永遠に回転
イーズアクション
一定の動きではなく徐々に変化させたりするアクション。
CCMoveTo* move = [CCMoveTo actionWithDuration:3 position:CGPointMake(100,200)]; CCEaseInOut* ease = [CCEaseInOut actionWithAction:move rate:4];//ゆっくりと加速したあと減速する [myNode runAction:ease];
CCActionEase
- CCEaseIn, CCEaseOut, CCEaseInOut
- CCEaseBounceIn, CCEaseBounceOut, CCEaseBounceInOut
- CCEaseElasticIn, CCEaseElasticOut, CCEaseElasticInOut
- CCEaseExponentialIn, CCEaseExponentialOut, CCEaseExponentialInOut
- CCEaseIn, CCEaseOut, CCEaseInOut
- CCEaseSineIn, CCEaseSineOut, CCEaseSineInOut
アクションシーケンス
通常、複数のアクションを登録するとすべてのアクションがそれぞれのタスクを同時に実行する。アクションを順番に実行するにはシーケンスにする。
CCTintTo *tint1 = [CCTintTo actionWithDuration:3 red:255 green:0 blue:0];
CCTintTo *tint2 = [CCTintTo actionWithDuration:3 red:0 green:0 blue:255];
CCTintTo *tint3 = [CCTintTo actionWithDuration:3 red:0 green:255 blue:0];
CCSequence *sequence = [CCSequence actions:tint1, tint2, tint3, nil];
[label runAction:sequence];
//RepeatForeverを使う場合
CCSequence *sequence2 = [CCSequence actions:tint1, tint2, tint3, nil];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:sequence2];
[label runAction:repeat];
インスタントアクション
プロパティでも変更可能な効果だがシーケンスに組み込める。
CCCallFuncアクション・・・シーケンス終了などのタイミングで通知メッセージを送信できる。
CCTintTo *tint1 = [CCTintTo actionWithDuration:3 red:255 green:0 blue:0];
CCTintTo *tint2 = [CCTintTo actionWithDuration:3 red:0 green:0 blue:255];
CCTintTo *tint3 = [CCTintTo actionWithDuration:3 red:0 green:255 blue:0];
CCCallFunc *func = [CCCallFunc actionWithTarget:self selector:@selector(onCallFunc)];
CCCallFuncN *funcN = [CCCallFuncN actionWithTarget:self selector:@selector(onCallFuncN)];
CCCallFuncND *funcND = [CCCallFuncND actionWithTarget:self selector:@selector(onCallFuncND:data:) data:background];
CCSequence *sequence = [CCSequence actions:tint1, func, tint2, funcN tint3, funcND, nil];
[label runAction:sequence];
0 件のコメント:
コメントを投稿