-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
_nextProjectile = [[CCSprite spriteWithFile:@"arrow.png"]retain];
_nextProjectile.position = imgArrow.position;
[imgArrow runAction:[CCSequence actions:
[CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
[CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
nil]];
//Some code
}
- (void)finishShoot {
// Ok to add now - we've finished rotation!
[self addChild:_nextProjectile];
[_projectiles addObject:_nextProjectile];
// Release
[_nextProjectile release];
_nextProjectile = nil;
}
当我点击弓箭两次时,我的箭头与另一个箭头重叠。
任何帮助?!
答案 0 :(得分:0)
在释放下一个箭头并触摸之前,您需要删除之前的箭头。我认为你正在制作一个射击游戏,当触摸屏幕时会释放箭头。我建议在动作完成时删除最后一个箭头
答案 1 :(得分:0)
尝试使用此代码,在添加之前我们已经删除了箭头,(如果有的话,修复语法错误)
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
[self removeChild:[self childWithTag:101]];
_nextProjectile = [[CCSprite spriteWithFile:@"arrow.png"]retain];
_nextProjectile.tag = 101;
_nextProjectile.position = imgArrow.position;
[imgArrow runAction:[CCSequence actions:
[CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
[CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
nil]];
//Some code
}