How to make SKScene a fixed width?

I am making a game based on spriteKit and wondering if I can make a fixed width for SKScene (to simplify the layout of sprites) and let it resize to the actual width of the screen, keeping the aspect ratio. Is it possible to achieve this goal and is it recommended (sprites will not be displayed explicitly due to resizing)?

+5
source share
2 answers

Providing a fixed-size scene is what we want to do in SpriteKit games. SpriteKit will scale the game for each device using the scaleMode settings (the default is.aspectFill). It is not a good idea to make the scene the size of the device or use .resizeFill for the zoom mode, as this will lead to huge inconsistencies on different devices. I was there before with 1 game, and it was an absolute nightmare.

So, we basically have 2 ways to do it right

1) Set the scene size for the iPad (for example, 1024x768-landscape, 768x1024 is a portrait. This was the default setting in Xcode 7.

You, as usual, simply show an additional background in the top / bottom (landscape) or left / right (portrait) on iPads.

Examples of games that show more on iPads:

Altos Adventure, Leos Fortune, Limbo, 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 option crop your game on the iPad.

Examples of games that show less on the iPad:

Lumino city, attack of the robot unicorn

The choice between these two options is up to you and depends on what kind of game you are making. I usually prefer to use option 1 and show more background on iPads.

Regardless of the scale mode, it is usually best to leave the default .aspectFill value. Thus, you will have a constant experience on all devices.

I would not do any random hacks where you manually change the scene or node sizes / scales on difference devices, you should let xCode / SpriteKit do it for you.

In code, you must initialize SKScene with your preferred size.

let gameScene = GameScene(size: CGSize(width: 1024, height: 768)) 

If you use the visual scene editor, you set the size of the scene directly in the inspector panel on the right.

Hope this helps

+3
source

Any resizing occurs with a performance limitation and resizing of artifacts such as blurry edges or others.

The size of the scene is determined by the ViewController when it instantiates the scene before it is presented. Isn't it better to create a scene with the same size as the actual screen size, and not change it even more?

0
source

Source: https://habr.com/ru/post/1265652/


All Articles