我有一个碰撞处理程序检测游戏结束情况,但是当火箭落地时(否则如果),标签变得可见没有问题,但是还有第二个触地即使仍然记录,然后火箭起飞再次,然后触摸禁用。有没有明显的事情我做错了?
-(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair rocket:(CCNode *)nodeA landingPad:(CCNode *)nodeB{
//if travelling too fast on landing..
if (_rocket.physicsBody.velocity.y < maximumVerticalVelocity){
_crashNotice.visible = TRUE;
crashed = TRUE;
[_rocket removeFromParentAndCleanup:YES];
self.userInteractionEnabled = FALSE;
}else if (_rocket.physicsBody.velocity.y > 0.01){
self.userInteractionEnabled = FALSE;
//show game won state
_scoreLabel.visible = FALSE;
_showScoreLabel.visible = TRUE;
}return TRUE;
}
答案 0 :(得分:0)
不是启用和禁用触摸,而是通过bool值处理。
在class.h文件中声明这个
bool mAllowTouch;
在Init / onEnter:
-(void)onEnter
{
[super onEnter];
mAllowTouch = true;
self.userInteractionEnabled = true;
}
在你的功能中
-(BOOL)ccPhysicsCollisionPreSolve
{
if(YOUR_CONDITION_TO_STOP_TOUCH)
{
mAllowTouch = false;
}
else
{
mAllowTouch = true;
}
}
在触控功能中,使用mAllowTouch处理您的触控。
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if(mAllowTouch)
{
//handle touch here.
}
}