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 的基础知识 ;) 《学习 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 回答