I'm using spritekit to make an iOS game, and I came across a problem I've never had before. I want my game to be available on multiple devices, so I'm dynamically sizing everything based on the screen size, which I'm obtaining by using UIScreen.mainScreen().bounds.size, as was recommended online.
It's returning a screen size of 667x375. However, when I place an object at half the height and half the width, expecting to see it in the middle of the screen, it's instead displayed in the lower left corner.
Curious, I had it print touch locations from mouse clicks and discovered that the top right corner returns 1024x764 when clicked.
I've never had this problem before, and this is my 3rd XCode project. Can anyone help me?
UIScreen.mainScreen().bounds.size
returns the size of your screen.
Sprite Kit uses a coordinate system different from a UIView
. The bottom left corner of the scene is (0, 0)
. The values increase as you move up and to the right, so the top-right corner will give you the maximal value.
A scene's contents are scaled to fit the view based on the scaleMode
property.
I suggest you re-read the Building Your Scene documentation.