初始化程序SKPhysicsBody返回意外的nil

时间:2020-07-25 07:54:11

标签: swift sprite-kit skphysicsbody

这是一年前工作的物理机构的代码,但由于某种原因现在没有。 在这里,我创建了物理实体,但实际上返回的是nil。

SKPhysicsBody中的每个元素:纹理和大小都不为零:

 let playerPlaneTexture = atlas.textureNamed("airplane_3ver2_13")
        print("###################")
        print("playerPlaneTexture")
        print(playerPlaneTexture)
        let playerPlane = PlayerPlane(texture: playerPlaneTexture)
        playerPlane.setScale(0.5)
        playerPlane.position = point
        playerPlane.zPosition = 40
        
        print("###################")
        print("playerPlane.size")
        print(playerPlane.size)
        playerPlane.physicsBody = SKPhysicsBody(texture: playerPlaneTexture, alphaThreshold: 0.5, size: playerPlane.size)

        print("###################")
        print("playerPlane.physicsBody")
        print(playerPlane.physicsBody)

这是控制台输出,您可以看到除PhysicalBody之外的所有内容都有价值:

###################

playerPlaneTexture

'airplane_3ver2_13.png'(300 x 210)

###################

playerPlane.size

(150.0,105.0)

2020-07-25 12:48:36.428596 + 0500 WarFly [5557:400140] PhysicsBody:可以 不能创建物理物体。

###################

playerPlane.physicsBody

1 个答案:

答案 0 :(得分:0)

找到解决方案。由于某种原因,现在的alpha阈值应该更低。所以现在如果我将其设置为0.2例如,一切正常。

相关问题