【发布时间】:2020-08-26 17:44:08
【问题描述】:
class GameScene: SKScene {
let player = SKSpriteNode(imageNamed: "spaceship")
struct PhysicsCategories {
static let None: UInt32 = 1
static let Player: UInt32 = 0b1
static let Obsticles: UInt32 = 0b10
static let Diamond: UInt32 = 0b100
}
func didBegin(_ contact: SKPhysicsContact) {
var body1 = SKPhysicsBody()
var body2 = SKPhysicsBody()
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
body1 = contact.bodyA
body2 = contact.bodyB
}
else {
body1 = contact.bodyB
body2 = contact.bodyA
}
if body1.categoryBitMask == PhysicsCategories.Player && body2.categoryBitMask == PhysicsCategories.Obsticles {
body1.node?.removeFromParent()
body2.node?.removeFromParent()
}
}
我想在钻石与玩家接触时将其移除,并在玩家与障碍物接触时移除它。 目前我无法注册他们之间的联系 我目前使用 Xcode 9.4.1 版。如果我将应用程序更新为,问题是否仍然存在
【问题讨论】:
标签: swift xcode sprite-kit skspritenode skphysicsbody