当两个玩家和怪物崩溃时,我想眨眼SpritekitNode
。我使用didBeginContact
中的代码:
-(void)didBeginContact:(SKPhysicsContact *)contact
{
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if ([firstBody.node.name isEqual: OBSTACLE_KEY] && ( [secondBody.node.name isEqual: PLAYER_KEY] ))
{
if ([kPref integerForKey:BUY_LIFES] > 0)
{
SKAction *blink = [SKAction sequence:@[[SKAction fadeOutWithDuration:0.25],
[SKAction fadeInWithDuration:0.25]]];
SKAction *blinkForever = [SKAction repeatAction:blink count:3];
[secondBody.node runAction: blinkForever];
int life = [kPref integerForKey:BUY_LIFES] - 1;
[kPref setInteger:life forKey:BUY_LIFES];
}
else
{
[kPref setInteger:sec forKey:HIGH_SCORE];
self.paused =YES;
}
}
}
它工作但是当怪物接触到玩家节点直到它连接到它时它会不断地调用didBeginContact
,我想设置如果怪物节点触摸玩家比它眨眼3次并且那段时间没有怪物可以触摸播放器节点。
请帮帮我。