2013年1月21日月曜日

CCRemoveFromParentActionって?


Kobold2dのuser-inputプロジェクトのコードで、以下が気になったので、調査。
id remove = [CCRemoveFromParentAction action];

[CCRemoveFromParentAction ation];って文字通りの意味だろうけど、どうやって使うのか、と。

で、Kobold2dのKobold2d Cocos2d Extensionsの中にクラスが定義されていました。

@implementation CCRemoveFromParentAction
-(void) startWithTarget:(id)target
{
[super startWithTarget:target];[target removeFromParentAndCleanup:YES];}
@end

superで親クラスがstartWithTargetというメソッドを実装している様子。

で、startWithTargetは、以下のCocos2dリファレンス(CCAction Class Reference)に定義が書かれていました。

http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_action.html#a791b44f936b12d01e2aab5df8af41bfb


- (void) startWithTarget:(id) target
called before the action start. It will also set the target.

なるほど。
親クラスで、actionがスタートする前に呼び出され、CCActionのターゲットがsetされている、と。
で、removeFromParentAndCleanup:YESで、削除される、と。

まあ、文字通りの意味ですが、ちょっとすっきりしました。

CCの接頭辞ですが、どうもKobold2dのエクステンションのようですね。

0 件のコメント:

コメントを投稿