作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个屋顶 Sprite 节点,我希望玩家 Sprite 节点能够从该节点反弹,但是当它们触摸它时,就会运行我的碰撞函数。屋顶和玩家物理类别:
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,但随后玩家就冲破了屋顶。如果您对此有所了解,请在下面留下任何建议或建议。谢谢您
最佳答案
如果您不希望发生 didBeginContact,请删除 contactTestBitmask
关于xcode - 我有两个物体,当碰撞时我想互相反弹,我怎样才能做到这一点,这样它就不会感觉到碰撞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35947461/
我是一名优秀的程序员,十分优秀!