SpriteKit游戏中的对象在iOS 7.1更新后停止碰撞

时间:2014-04-06 22:05:29

标签: ios collision-detection sprite-kit bitmask

我的spriteKit游戏中的对象在iOS 7.1更新后停止了碰撞。这包括屏幕的边界,因此角色只是在屏幕上运行。我使用位掩码来检测冲突并处理didBeginContact委托方法中的冲突。我将添加代码以添加我的SKNodes。提前致谢。

//main character 
self.girl = [SKSpriteNode spriteNodeWithImageNamed:@"pixelgirl"];
self.girl.position = CGPointMake(self.size.width / 2, self.size.height * 0.2);
[self addChild:self.girl];        
self.girl.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.girl.size.height / 4];
self.girl.physicsBody.dynamic = YES;
self.girl.physicsBody.affectedByGravity = NO;
self.girl.physicsBody.mass = 0.02;
self.girl.physicsBody.allowsRotation = NO;
self.girl.physicsBody.categoryBitMask = girlCategory;
self.girl.physicsBody.contactTestBitMask = tallTreeCategory | uglyTreeCategory | shortTreeCategory;

//contact object 
SKSpriteNode *pixelShort = [SKSpriteNode spriteNodeWithImageNamed:@"pixelshort"];
pixelShort.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:pixelShort.size.width / 2]; //2
pixelShort.physicsBody.dynamic = NO;
pixelShort.physicsBody.categoryBitMask = uglyTreeCategory;

- (void)didBeginContact:(SKPhysicsContact *)contact
{

__block BOOL isRotating;

[self performSelector:@selector(moveDog) withObject:Nil afterDelay:.3];

isRotating = NO;

if (!isRotating) {
    SKAction* action0 = [SKAction scaleXTo:1.0 duration:0.05];
    SKAction* action1 = [SKAction scaleXTo:0.1 duration:0.05];
    SKAction* action2 = [SKAction scaleXTo:-0.1 duration:0.05];
    SKAction* action3 = [SKAction scaleXTo:-1.0 duration:0.05];

    SKAction* action = [SKAction sequence:@[action0,action1,action2, action3]];

    [self.girl runAction:action completion:^{
        isRotating = YES;
    }];

    }

}

1 个答案:

答案 0 :(得分:1)

您的问题是scaleXTo:-1.0。我使用完全相同的命令来镜像我的一个精灵,并且一旦我这样做,小家伙就停止响应所有联系人。删除它,一切都很好。