我有一个屋顶Sprite Node,我希望玩家精灵节点能够反弹,但当他们触摸它时会运行我的碰撞功能。 屋顶和球员物理类别:
struct PhysicsCatagory {
static let Player : UInt32 = 0x1 << 1
static let Roof : UInt32 = 0x1 << 6
}
玩家和屋顶代码:
Player = SKSpriteNode(imageNamed: "plane")
Player.size = CGSize(width: 60, height: 70)
Player.physicsBody = SKPhysicsBody(rectangleOfSize: Player.size)
Player.position = CGPoint(x: self.frame.width / 2 - Player.frame.width, y: self.frame.width / 2)
Player.physicsBody?.categoryBitMask = PhysicsCatagory.Player
Player.physicsBody?.collisionBitMask = PhysicsCatagory.Ground | PhysicsCatagory.Mine | PhysicsCatagory.Ep | PhysicsCatagory.Bullet
Player.physicsBody?.contactTestBitMask = PhysicsCatagory.Ground | PhysicsCatagory.Mine | PhysicsCatagory.Ep | PhysicsCatagory.Bullet
Player.physicsBody?.affectedByGravity = false
Player.physicsBody?.dynamic = false
Player.zPosition = 4
Roof.size = CGSize(width: self.frame.width, height: 40)
Roof.physicsBody = SKPhysicsBody(rectangleOfSize: Roof.size)
Roof.position = CGPoint(x: self.frame.width / 2, y: self.frame.height - 20)
Roof.physicsBody?.categoryBitMask = PhysicsCatagory.Roof
Roof.physicsBody?.affectedByGravity = false
Roof.physicsBody?.dynamic = false
Roof.zPosition = 4
这是我发生碰撞时的代码:
func didBeginContact(contact: SKPhysicsContact) {
game = false
end = true
soundy = false
self.removeAllChildren()
self.removeAllActions()
endScreen()
}
我已经尝试将他们的身份改为0,但玩家只是穿过了屋顶。如果您对此有任何了解,请在下面留下任何建议或建议。谢谢
答案 0 :(得分:0)
删除contactTestBitmask