Why won't my SKSpriteNodes appear in the scene?

萝らか妹 提交于 2019-12-06 17:33:32

The Problem

Your sprites are not visible because your scene is not completely within the simulator's window. By default the scene's size is 1024 x 768 (specified by GameScene.sks), while the simulator is displaying only 375 x 667 points (if you selected the iPhone 6/6s simulator). Unless the scene's size is set correctly, the bottom-left corner of the simulator's window will not be the (0,0) position of your scene.

To correct this issue,

Method 1:

Change the scene's size property in GameScene.sks to match the size of the view. I suggest you set the scene size to 375 x 667 (iPhone 6/6s). If you do this and set the scene's scaleMode property to .AspectFill (the default value), SpriteKit will automatically scale the scene to fit in the view of the iPhone 6+, 6s+, 5, and 5s. This will save you time when porting your game to these devices.

Method 2: In your view controller, replace this

scene.scaleMode = .AspectFill

with this

scene.scaleMode = .ResizeFill

Warning: Using this method will work but may require additional effort to port your game to other iOS devices with a different screen size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!