0

タイマーに基づいて敵のスプライトをリスポーンしたいので、何か提案をいただければ幸いです。コード例をいくつか示していただければ幸いです。

   -(void)addEnemyAtX:(int)x y:(int)y {
  CCSprite *enemy = [CCSprite spriteWithFile:@"enemy1.png"];
  enemy.position = ccp(x, y);
  [self addChild:enemy];
  [self animateEnemy: enemy];}


  - (void) enemyMoveFinished:(id)sender {
CCSprite *enemy = (CCSprite *)sender;

    [self animateEnemy: enemy];
 }// a method to move the enemy 10 pixels toward the player
 - (void) animateEnemy:(CCSprite*)enemy
    {
    // speed of the enemy
     ccTime actualDuration = 0.3;

     // Create the actions
        id actionMove = [CCMoveBy actionWithDuration:actualDuration
                                                    position:ccpMult(ccpNormalize(ccpSub(player.position,enemy.position)), 10)];
     id actionMoveDone = [CCCallFuncN actionWithTarget:self
                                         selector:@selector(enemyMoveFinished:)];
          [enemy runAction:
                 [CCSequence actions:actionMove, actionMoveDone, nil]];



         }
4

1 に答える 1

0

最初に Cocos2D の基本を学ぶべきだと思います ;) 本「Learning Cocos2D」でかなり詳しく説明されています - 私はそれをお勧めします! それにもかかわらず、ここにあなたが望むコード行がありますが、それが有用かどうかは疑問です;)

action = [CCSpawn actions:
          [CCAnimate actionWithAnimation:animation
break;
restoreOriginalFrame:NO],
[CCMoveTo actionWithDuration:2.4f
 position:ccp([self position].x +
 nil];
xPositionOffSet,
[self position].y)],
于 2012-06-14T10:20:27.983 に答える