0
-(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;
}

当我点击弓两次时,我的箭头重叠在一起。

有什么帮助吗?!在此处输入图像描述

4

2 回答 2

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 

}
于 2013-04-22T19:04:25.727 回答
0

您需要先删除上一个箭头,然后才能通过触摸释放下一个箭头。我认为您正在制作一个射击游戏,当触摸屏幕时会释放箭头。我建议在操作完成后删除最后一个箭头

于 2013-04-22T13:06:10.593 回答