SKSpriteNode .run不起作用或不起作用

问题描述 投票:0回答:1

我试图找到以下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")
        })

    }
swift sprite-kit skspritenode skaction
1个回答
1
投票

它仍然不清楚,为什么它会导致问题,但是在我尝试在代码中的某个位置设置其速度后,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
        }))
© www.soinside.com 2019 - 2024. All rights reserved.