林这段代码向上火:Cocos2D检查sprite是否在屏幕外?使用
- (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];
}
,但我忘了触摸结束时才调用。
一个快速和肮脏的解决方案,这正是你的回答虽然 – igrek
或不准确的问题,因为它没有检查它是否在屏幕上或不 – igrek