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

标签 ios collision-detection sprite-kit bitmask

我的 spriteKit 游戏中的对象在 iOS 7.1 更新后停止碰撞。这包括屏幕的边界,因此角色刚好跑出屏幕。我使用位掩码检测碰撞并在 didBeginContact 委托(delegate)方法中处理碰撞。我将添加有关如何添加 SKNode 的代码。提前致谢。

//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;
    }];

    }

}

最佳答案

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

关于ios - iOS 7.1 更新后 SpriteKit 游戏中的对象停止碰撞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22900599/

相关文章:

ios - 如何在 Xcode 中修复 "Type of expression is ambiguous without more context"

ios - 为什么当我执行 removefromsuperview 时内存仍然存在?

objective-c - 将 UISearchBar 锁定到 TableView 的顶部

c++ - 如何进行正确的 2d 网格到圆碰撞检测

python - Pygame - 经过一段时间后删除/杀死 Sprite ,无需轮询

swift - 在 SpriteKit 中附加 SpriteNode

swift - 当敌人靠近时玩家不会检测到碰撞

iOS 应用程序 : Window rotation always Portrait instead of Landscape

ios - OCMock 在被测代码中自动使用模拟实例?

Delphi自定义动画-碰撞检测