我使用此代码向上触发:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent* )event
{
//Spawn the bullet
CCSprite * projectile = [CCSprite spriteWithFile:@"Projectile.png" rect:CGRectMake(0, 0, 17.5, 10)];
projectile.position = ccp(donk.position.x , 50);
[self addChild:projectile];
//Actualy Fire
[projectile runAction: [CCMoveTo actionWithDuration:.2 position: ccp (donk.position.x , 350)]];
}
它像我想要的那样工作,但是我如何使用 if 语句来检查弹丸是否离开屏幕顶部,以便我可以将其移除?
我尝试使用这个:
if (projectile.position.y >= 330) {
CCLOG(@"Removed");
[self removeChild:projectile cleanup:YES];
}
但我忘记了 touchesended 只被调用一次。