我正在编写一个SpriteKit游戏,我正在尝试添加相当于Cocos2D的传感器。我的问题是我的传感器不断推动其他精灵,但这不是我想要的。我希望传感器能够与其他精灵重叠,而不是推动它们。我该如何解决?这是我为传感器添加的代码:
bubble.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(50))
bubble.physicsBody?.dynamic = false
bubble.physicsBody?.allowsRotation = false
bubble.physicsBody?.affectedByGravity = false
这是我的碰撞方法:
func didBeginContact(contact: SKPhysicsContact) {
let collision:UInt32 = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask)
if collision == (playerCategory | crateCategory) {
NSLog("Game Over")
var myLabel = SKLabelNode(fontNamed: "Arial")
myLabel.text = "GAME OVER"
myLabel.fontSize = 50
myLabel.color = SKColor.blueColor()
myLabel.position = (CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5))
self.addChild(myLabel)
fisherman.physicsBody?.dynamic = false
fisherman.removeFromParent()
fish.physicsBody?.dynamic = false
fish.removeFromParent()
crate.physicsBody?.dynamic = false
crate.removeFromParent()
crateDuplicate.physicsBody?.dynamic = false
crateDuplicate.removeFromParent()
}
if collision == (playerCategory | bubbleCategory) {
NSLog("Bubble Contact")
bubbleDuplicate.removeAllActions()
bubbleDuplicate.removeFromParent()
bubble.removeAllActions()
bubble.removeFromParent()
bubbleDuplicate.setScale(0)
bubble.setScale(0)
bubbleDuplicate.alpha = 0
}
}
答案 0 :(得分:3)
将collisionBitMask
设置为0,因此将忽略此特定对象与其他对象的所有碰撞。