sprite-kit
물리학
수색…
didBeginContact 메서드에서 노드를 올바르게 제거하는 방법 (여러 연락처)
// PHYSICS CONSTANTS
struct PhysicsCategory {
static let None : UInt32 = 0
static let All : UInt32 = UInt32.max
static let player : UInt32 = 0b1 // 1
static let bullet : UInt32 = 0b10 // 2
}
var nodesToRemove = [SKNode]()
// #-#-#-#-#-#-#-#-#-#-#-#-#-#-#
//MARK: - Physic Contact Delegate methods
// #-#-#-#-#-#-#-#-#-#-#-#-#-#-#
func didBegin(_ contact: SKPhysicsContact) {
var one: SKPhysicsBody
var two: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
one = contact.bodyA
two = contact.bodyB
} else {
one = contact.bodyB
two = contact.bodyA
}
// PLAYER AND BULLET
if one.categoryBitMask == PhysicsCategory.player && two.categoryBitMask == PhysicsCategory.bullet {
nodesToRemove.append(one.node!) // remove player
nodesToRemove.append(two.node!) // remove bullet
}
}
override func didFinishUpdate()
{
nodesToRemove.forEach(){$0.removeFromParent()}
nodesToRemove = [SKNode]()
}
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow