需要通过按下炸弹按钮连续在cocos2d游戏中放置一个炸弹

时间:2013-06-08 15:08:36

标签: cocos2d-iphone

现在正在移除第一个炸弹之后放置炸弹,现在要求是连续放置炸弹并且炸弹只有一张精灵表,如果放置第一枚炸弹并立即放置第二枚炸弹就会出现问题第一枚炸弹没有移走。 Plz帮助我并且是cocos2d的新手

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
   @"Bombs.plist"];
   _spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Bombs.png"];
   [_tileMap addChild:_spriteSheet z:100 ];NSMutableArray *walkAnimFrames = 
    [NSMutableArray       array];
    for(int i = 1; i <=20; ++i)
    {
    [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] 
    spriteFrameByName:     [NSString stringWithFormat:@"Bomb_%d.png", i]]]; 
    }
    CCAnimation *walkAnim = [CCAnimation   animationWithFrames:walkAnimFrames delay:0.1f];
    _bomb= [CCSprite spriteWithSpriteFrameName:@"Bomb_1.png" ];
     _bomb.position =_player.position;
    [_bomb runAction:[CCSequence actions:[CCDelayTime actionWithDuration:0.2f],
   [CCAnimate   actionWithAnimation:walkAnim],[CCCallFuncN actionWithTarget:
   self    selector:@selector(spriteDone:)],nil]];
    [_spriteSheet addChild:_bomb z:100];


// selector to remove bomb

- (void)spriteDone:(id)sender { 
    [_spriteSheet removeChild:_bomb cleanup:YES];
     _bombRemoved =TRUE; NSLog(@"Bool value: %d",_bombRemoved); 
}

1 个答案:

答案 0 :(得分:0)

编辑2:在动画完成后和下次触摸时使某些炸弹消失。

// where you determine the touch should add a bomb
if(_bomb) {
  [_bomb removeFromParentAndCleanup:YES];
  _bomb = nil;
}

// do your stuff creating new _bomb object

// when you create the action, change to :

[_bomb runAction:[CCSequence actions:
   [CCDelayTime actionWithDuration:0.2f],
   [CCAnimate   actionWithAnimation:walkAnim],
   [CCCallBlock actionWithBlock:^{ 
          [_bomb removeFromParentAndCleanup:YES];
          _bombRemoved = YES;
          _bomb=nil;
      }
   ],nil]
];