0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cocos2dでアクション実行完了後に処理を行う方法

Posted at

cocos2dでCCActionを使ってアクションを実行した後に何らかの処理を行いたい場合があります。
その場合、

うまくいかないコード
//アクション(フェードアウト)
CCFadeOut *fadeOut = [CCFadeOut actionWithDuration:1.0];
//何らかの処理

としても、
フェードアウトアクションの完了を待ってくれず、すぐに処理が行われてしまいます。

方法1

そこで、処理を行うメソッドを別に用意(例:hoge)し、
CCSequenceにアクションとメソッドの順に登録して実行すれば、順次処理してくれます。

//アクション(フェードアウト)
CCFadeOut *fadeOut = [CCFadeOut actionWithDuration:1.0];
//処理関数を生成
CCCallFunc *hogeFunc = [CCCallFunc actionWithTarget:self selector:@selector(hoge)];
//シーケンシャルにアクションを実行
[self runAction:[CCSequence actions:fadeOut, hogeFunc, nil]];
- (void)hoge {
	//何らかの処理

}

CCCallFuncの他に、CCCallFuncN(引数にsenderが付く)、CCCallFuncND(senderや任意の引数がつく)があります。

方法2

もしくはブロックを使う場合は、

CCFadeOut *fadeOut = [CCFadeOut actionWithDuration:1.0];
CCCallBlock *hogeFunc = [CCCallBlock actionWithBlock:^{
    //何らかの処理

}];
[self runAction:[CCSequence actions:fadeOut, hogeFunc, nil]];

としても可能です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?