TalkingCode
TalkingCode

Reputation: 13557

Dealing with different screen sizes in a SpriteKit game

I am working a some kind of Breakout game with SpriteKit and I am not sure how to handle the different screen sizes of the iPhones.

My display is 375 points wide. In the game I want to have 5 sprites in a row. So one sprite is 375 / 5 = 75 points wide. I created a PNG image also 75 pixel wide. (Also a 2x and 3x version). So far it works well. The sprites are optimally distributed across the screen. But there are also devices with a screen width of 414 or 320 points. How do I deal with this?

Should I create completely different sprites (and bitmaps) for these devices? Then I also need different parameters to distribute them on the screen.

Or is there a completely different way to deal with it that I just don't know?

Upvotes: 2

Views: 213

Answers (1)

Bhavin p
Bhavin p

Reputation: 102

Maybe instead of using an absolute value like 375 points. You can instead use the screen Size from the current device.

let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height

then you can divide the screenWidth by 5 and get your spacing. This will not affect your PNG with a width of 75 px. I am pretty sure that the image would maintain its aspect ratio so I wouldn't be too concerned with that. I have done something like this in the past and no matter the size of the PNG it always looks fine.

And the fact that you have your 1x, 2x, 3x should maintain the quality of your PNG.

Upvotes: 1

Related Questions