cocos2d-lesson2-yourfirstgame 2

Sprite でキャラクタは、表示できたので、つぎは
Making Things Move です。
動かしたいでしょう?ということで
2つの手法があるそうです。
  1. Use an Action to tell the sprite to automatically move to a target position over a certain amount of time; or
  2. Move the sprite yourself in a method that gets called periodically during the game.
最初に、2.の方法から紹介されています。

// schedule a repeating callback on every frame

[self schedule:@selector(nextFrame:)]; }

-(id) init の if

セクションに追加します。


次に以下のコードを-(id) initの後ろ、- (void) dealloc の前に追加します。


- (void) nextFrame:(ccTime)dt {

  seeker1.position = ccp( seeker1.position.x + 100*dt, seeker1.position.y );

  if (seeker1.position.x > 480+32) {

    seeker1.position = ccp( -32, seeker1.position.y );

  }

}



無事に動きました。


なんで動くか、英語の解説読んで考えましょう!


速く動かすには、

ccp( seeker1.position.x + 100*dt,


ここの数字を変えれば良いんじゃないかな?


コメント