【发布时间】:2017-08-04 15:07:29
【问题描述】:
我有两个想要相互碰撞的实体。我有一个结构来跟踪不同的物理类别:
struct PhysicsCategory {
static let Player: Int32 = 0x1 << 1
static let Obstacle: Int32 = 0x1 << 2
static let Ground: Int32 = 0x1 << 3
}
我希望我的 Player 节点与我的 Obstacle 节点发生冲突。这是我的 Player 节点的物理特性:
self.physicsBody = SKPhysicsBody(rectangleOf: (self.size))
self.physicsBody?.isDynamic = true
self.physicsBody?.categoryBitMask = UInt32(PhysicsCategory.Player)
self.physicsBody?.collisionBitMask = UInt32(PhysicsCategory.Obstacle)
self.physicsBody?.collisionBitMask = UInt32(PhysicsCategory.Ground)
这是我的障碍节点的物理原理
self.physicsBody = SKPhysicsBody(rectangleOf: self.size)
self.physicsBody?.categoryBitMask = UInt32(PhysicsCategory.Obstacle)
self.physicsBody?.collisionBitMask = UInt32(PhysicsCategory.Player)
self.physicsBody?.collisionBitMask = UInt32(PhysicsCategory.Ground)
self.physicsBody?.isDynamic = true
self.physicsBody?.velocity = CGVector(dx: -240, dy: 0)
self.physicsBody?.linearDamping = 0
self.physicsBody?.friction = 0
当他们穿越路径时,他们只是互相穿过。但是,它们都正确地与地面相撞。我做错了什么?
【问题讨论】:
-
编程的基本原理告诉你,如果你写 x = 1 并且在 x = 2 之后,你的 x 是 2
标签: swift sprite-kit skphysicsbody