ラベル action の投稿を表示しています。 すべての投稿を表示
ラベル action の投稿を表示しています。 すべての投稿を表示

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のエクステンションのようですね。

CCMoveToとCCMoveBy

CCMoveToとCCMoveByの違いを理解するために、リファレンスを参照。
CCMoveByはCCMoveToを継承し、deltaPosition(フレームごとのポジション移動量?)が指定されている。

deltaはどうやら、frameの差分の様子。
参考1 (どこかの質疑応答)
参考2「Unity におけるフレームと Update」

00134 @interface CCMoveTo : CCIntervalAction <NSCopying>
00135 {
00136         CGPoint endPosition;
00137         CGPoint startPosition;
00138         CGPoint delta;
00139 }
00141 +(id) actionWithDuration:(ccTime)duration position:(CGPoint)position;
00143 -(id) initWithDuration:(ccTime)duration position:(CGPoint)position;
00144 @end
00145 
00150 @interface CCMoveBy : CCMoveTo <NSCopying>
00151 {
00152 }
00154 +(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
00156 -(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
00157 @end

CCMoveToは、特定地点(絶対位置)への移動。一度移動したら、そこで終了。
CCMoveByは、現在地からの相対的移動。絶対位置の指定ではなく。どんどん移動できる。現在地から、次の地点へ、同量の距離を。

ということらしい。

どんどんSpriteを動かす場合には、CCMoveByが便利。

2013年1月19日土曜日

texture packerを使ったキャラクターのアニメ実装動画

cocos2dやKobold2dでspriteを複数一枚の画像に登録し、メモリ使用量を減らすためのツールに「texture packer」がある。
http://www.codeandweb.com/texturepacker

これを使って、動くキャラクターを実装していく様子をビデオに上げている方がいた。
http://vimeo.com/19906038
ナルホド、という感じ。

コードの書き方も参考になった。

何度か見返そう、と思ったので、メモ。
Mmm Cocoa - TexturePacker and Animated Sprites from Tom Glenn on Vimeo.