How do I size sprites in a universal sprite kit ga

2019-06-13 05:47发布

问题:

I'm relatively new to swift programming. I have made an app where I didn't use SpriteKit and I would size most views by scaling down the images to a multiple of the screens width and height. Not sure if this is the best tactic, but it worked and I was able to build an app that looked good on all devices.

With spritekit and the scene.sks files, I don't have the option of auto-layouts to size my sprites like I did before. There isn't a lot of content about universal apps online, so I'm struggling to find a solution.

My question is how do I go about sizing objects and making sure my scenes look the same across different devices?

If you have a good example that could explain this that would be very helpful. Thank you!

回答1:

What we usually do in SpriteKt is to give the SKScene a fixed size and let SpriteKit do the scaling for you on different devices.

So basically we have 2 ways to do it correctly

1) Set scene size to iPad (e.g 1024x768 -landscape, 768x1024 - portrait). This was the default setting in Xcode 7.

You than usually just have/show some extra background at the top/bottom (landscape) or left/right (portrait) on iPads which gets cropped on iPhones.

Examples of games that show more on iPads / crop on iPhones:

Altos Adventure, Leos Fortune, Limbo, The Line Zen, Modern Combat 5.

2) Apple changed the default scene size in xCode 8 to iPhone 6/7 (750*1334-Portait, 1337*750-Landscape). This setting will crop your game on iPads.

Examples of games that show less on iPads:

Lumino City, Robot Unicorn Attack

Choosing between those 2 options is up to you and depends what game you are making. I usually prefer to use option 1 and show more background on iPads.

Regardless of scene size scale mode is usually best left at the default setting of .aspectFill.

You would use the Universal asset slot and/or device specific images. This way you will have a consistent experience on all devices

Spritekit scale full game to iPad

How to make SKScene have fixed width?

Hope this helps