문제 설명
.removeFromParent()가 작동하지 않음 (.removeFromParent() not working)
관련된 코드입니다. 총알이 명중하고 적군이 사라지거나 그 반대의 경우가 발생한다고 가정합니다. 전혀 운동하지 않음 :(
func didBeginContact(contact: SKPhysicsContact) {
var firstBody : SKPhysicsBody = contact.bodyA
var secondBody : SKPhysicsBody = contact.bodyB
if ((firstBody.categoryBitMask == PhysicsCatagory.Enemy) && (secondBody.categoryBitMask == PhysicsCatagory.Bullet) || (firstBody.categoryBitMask == PhysicsCatagory.Bullet) && (secondBody.categoryBitMask == PhysicsCatagory.Enemy)) {
CollisionWithBullet(firstBody.node as! SKSpriteNode, Bullet: secondBody.node as! SKSpriteNode)
}
}
func CollisionWithBullet(Enemy: SKSpriteNode, Bullet: SKSpriteNode) {
Enemy.removeFromParent()
Bullet.removeFromParent()
}
게임은 다음과 같습니다.
참조 솔루션
(by Darcey Mckelvey)