如何在cocos2d中设置基于计时器的重构系统?

时间:2012-06-14 10:02:22

标签: iphone xcode ios5 cocos2d-iphone sprite

我想根据计时器重新生成敌人的精灵,任何建议都会受到赞赏。 如果你向我展示一些代码示例,那就太棒了。

   -(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]];



         }

1 个答案:

答案 0 :(得分: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)],