为什么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文件,我都会得到零。