【问题标题】:Initializer SKPhysicsBody returns unexpected nil初始化程序 SKPhysicsBody 返回意外的 nil
【发布时间】:2020-07-25 07:54:11
【问题描述】:

这是一年前有效但现在由于某种原因无效的物理体代码。 这里我创建了物理体,但它实际上返回 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)

这是控制台输出,您可以在其中看到除了physicsBody之外的所有内容:

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

playerPlaneTexture

'airplane_3ver2_13.png' (300 x 210)

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

playerPlane.大小

(150.0, 105.0)

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

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

playerPlane.physicsBody

【问题讨论】:

    标签: swift sprite-kit skphysicsbody


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多