我试图找到以下skspritenode奇怪行为的来源:有时它只是不执行.run(...)或执行不完整。我找不到任何规律性,所以我想知道,如果这是一个已知的问题?
func didBegin(_ contact: SKPhysicsContact) {
let firstBody = contact.bodyA
let secondBody = contact.bodyB
if firstBody.categoryBitMask == CollisionBitMask.birdCategory && secondBody.categoryBitMask == CollisionBitMask.BonusCategory {
secondBody.node?.removeFromParent()
print("contact began")
firstBody.node?.run(SKAction.run {
print("run works")
})
}
else if firstBody.categoryBitMask == CollisionBitMask.BonusCategory && secondBody.categoryBitMask == CollisionBitMask.birdCategory {
firstBody.node?.removeFromParent()
print("contact began")
secondBody.node?.run(SKAction.run {
print("run works")
})
}
它仍然不清楚,为什么它会导致问题,但是在我尝试在代码中的某个位置设置其速度后,skspritenode没有执行.run:
enumerateChildNodes(withName: "bird", using: ({
(node, error) in
let bg = node as! SKSpriteNode
bg.physicsBody?.affectedByGravity = false
bg.speed = 0 // <- after removing this, everything works fine
}))