Swift IOS Spritekit Scaling Sprite Size based on device size

I've been tinkering with SpriteKit, Xcode and Swift for the past few weeks, and despite a lot of research, I still have to figure out how to best manage sprite size across devices.

In my game, I found a somewhat circular way to control the sprite size and position so that my sprites are somewhat consistent across devices by manually adjusting characteristics such as size, font size and position if operators checking device height. Ideally, I would like all my game views, including the sprites they place, to be proportional to the size of the device. I've tried tinkering with various SKSceneScaleModes but nothing does the trick.

My question is: What is the most efficient way to control sprite size and positioning between devices in SpriteKit (more specifically, in Swift)? I don't care too much about iPad support, mostly iPhone 4s - 6 plus only. Thank.

+3


source to share


1 answer


Imo, just the scaling relative to the GameScene size is good enough. In GameViewController

I am initializing the scene as view.bounds.size

. When you create your sprite, just make a call setScale

to make it proportional view.bounds.size

. Because it is view.bounds.size

based on how big the screen is, you will get proportionally larger images for larger shielded devices.



+6


source







All Articles