作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图不接触穴居人和其他带有碰撞位掩码的图像,但我的穴居人击中了一切。
func addCaveManBitMasks(){
caveManNode.physicsBody?.categoryBitMask = PhysicsCategory.caveman
caveManNode.physicsBody?.contactTestBitMask = PhysicsCategory.tri | PhysicsCategory.trex | PhysicsCategory.newblock | PhysicsCategory.fireBall | PhysicsCategory.waterblock | PhysicsCategory.secondwaterblock | PhysicsCategory.star
caveManNode.physicsBody?.collisionBitMask = PhysicsCategory.newblock
}
func addTriBitMasks(){
triImage.physicsBody?.categoryBitMask = PhysicsCategory.tri
triImage.physicsBody?.contactTestBitMask = PhysicsCategory.caveman
triImage.physicsBody?.collisionBitMask = 0
}
func addRexBitMasks(){
tRexImage.physicsBody?.categoryBitMask = PhysicsCategory.trex
tRexImage.physicsBody?.contactTestBitMask = PhysicsCategory.caveman
tRexImage.physicsBody?.collisionBitMask = 0
}
func addNewBlockManBitMasks(){
newBlockImageNode.physicsBody?.categoryBitMask = PhysicsCategory.newblock
newBlockImageNode.physicsBody?.contactTestBitMask = PhysicsCategory.caveman | PhysicsCategory.steg
newBlockImageNode.physicsBody?.collisionBitMask = PhysicsCategory.caveman
}
func addFireBallBitMasks(){
fireBall.physicsBody?.categoryBitMask = PhysicsCategory.fireBall
fireBall.physicsBody?.contactTestBitMask = PhysicsCategory.caveman
fireBall.physicsBody?.collisionBitMask = 0
}
func addStarBitMasks(){
onScreenStar.physicsBody?.categoryBitMask = PhysicsCategory.star
onScreenStar.physicsBody?.contactTestBitMask = PhysicsCategory.caveman
onScreenStar.physicsBody?.collisionBitMask = 0
}
struct PhysicsCategory {
static let caveman: UInt32 = 0x1 << 0
static let tri: UInt32 = 0x1 << 1
static let trex: UInt32 = 0x1 << 2
static let fireBall: UInt32 = 0x1 << 3
static let steg: UInt32 = 0x1 << 4
static let ptero: UInt32 = 0x1 << 5
static let waterblock: UInt32 = 0x1 << 6
static let secondwaterblock: UInt32 = 0x1 << 7
static let newblock: UInt32 = 0x1 << 8
static let star: UInt32 = 0x1 << 9
static let food: UInt32 = 0x1 << 10
}
tri、rex、fireball 和 newblock 彼此不接触,这是完美的,但我也需要穴居人做同样的事情。穴居人应该只碰撞 与它所做的新方 block 。我很困惑,非常感谢您的解释
最佳答案
这是因为您将所有其他对象 collisionBitMask
设置为与穴居人相同。将那些其他对象的碰撞位掩码更改为您尚未在另一个节点上使用的位掩码,因为它的类别,你会很好。
关于ios - *碰撞*通过位掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43418476/
我是一名优秀的程序员,十分优秀!