Cocos2d iphone 如何为每两次拍摄隐藏一个精灵?
我正在开发一个cocos2d游戏,我将用子弹射击一枚导弹,在这里,每当我射击导弹时,导弹必须隐藏,但我的问题是,每2发子弹,我必须隐藏一枚导弹 这是我的密码Cocos2d iphone 如何为每两次拍摄隐藏一个精灵?,cocos2d-iphone,Cocos2d Iphone,我正在开发一个cocos2d游戏,我将用子弹射击一枚导弹,在这里,每当我射击导弹时,导弹必须隐藏,但我的问题是,每2发子弹,我必须隐藏一枚导弹 这是我的密码 if (CGRectIntersectsRect(bullet.boundingBox, missile.boundingBox)){ target--; [objectiveLabel setString:[NSString stringWithFormat:@"%d",target]]; bullet
if (CGRectIntersectsRect(bullet.boundingBox, missile.boundingBox)){
target--;
[objectiveLabel setString:[NSString stringWithFormat:@"%d",target]];
bullet.visible = NO;
missile.visible = NO;
continue;
}
这段代码是为单拍,但我想为2拍相同的功能
有谁能告诉我如何完成这项任务吗
提前感谢为您的导弹对象添加一个属性,并在代码中对其进行测试,大致如下:
@property(nonatomic,readwrite) NSUInteger shotsToDeath;
初始化导弹时:
-(id) init {
if(self=[super init]) {
// add the following line to your init
self.shotsToDeath = 1; // default
return self;
}
return nil;
}
当你制造导弹时,你可以增加射杀他的次数:
missile.shotsToDeath = 2; // if appropriate (depends on difficulty level ?)
最后,在上面的例行公事中:
if (CGRectIntersectsRect(bullet.boundingBox, missile.boundingBox)){
missile.shotsToDeath--;
if(0==missile.shotsToDeath {
target--;
[objectiveLabel setString:[NSString stringWithFormat:@"%d",target]];
missile.visible = NO;
}
bullet.visible = NO;
continue;
}
没有测试,没有编译,只是为了这个想法。小心递减,确保您不会得到-1:)嗨,YvesLeBorg谢谢您的快速回复,但是当我尝试实现您发送的代码时,它显示了一个错误,例如在对象类型上找不到属性shotsToDeath。所以请你帮我解决这个问题好吗?提前谢谢