为什么SKSpriteNode(fileNamed :)在iOS中使用Swift生成nil?

时间:2019-05-11 22:09:11

标签: ios swift sprite-kit skspritenode

为什么SKSpriteNode的init(fileNamed :)产生nil?

我尝试了以下代码。我只显示与问题相关的代码:

let road = SKSpriteNode(fileNamed: "road.png")

override func didMove(to view: SKView) {

    print("road", road as Any) // road nil
    if let road = self.road {
        road.position = view.center
        road.physicsBody = SKPhysicsBody(rectangleOf: road.size)
        print(road.physicsBody?.isDynamic as Any, "!")
        road.physicsBody?.pinned = true
        addChild(road)
    }

}

无论图像文件是常规png还是动画png文件,我都会得到零。

0 个答案:

没有答案