-2

现在正在移除第一个炸弹后放置炸弹,现在要求是连续放置炸弹,并且该炸弹只有一个精灵表,如果放置第一个炸弹并立即放置第二个炸弹而不是第一个炸弹,就会出现问题不删除。请帮助我,我是 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); 
}
4

1 回答 1

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]
];
于 2013-06-08T15:55:54.700 回答