Scale sprite kit game for all devices

橙三吉。 提交于 2019-12-25 18:59:10

问题


When creating my game in spriteKit I used the game size 1080x1920. Now however If I am to run it on Ipad it looks bizarre. Is there an easy fix? I am simply worried that my app will get rejected. Thank you in advance?


回答1:


When you present the scene's you also set the aspect ratio.

example :

if let scene = SKScene(fileNamed: "GameScene") {
    // Set the scale mode to scale to fit the window
    scene.scaleMode = .aspectFill

    // Present the scene
    view.presentScene(scene)
}

There are 4 different aspect radios you can set

  • aspectFit
  • aspectFill
  • fill
  • resizeFill

You can find out about the 4 different types here in the apple documents.

It looks to me that you currently have it set to aspectFill but you would be better off using aspectFit. This will create a black bar on the top and bottom on some devices but it will keep the aspect ratio the same.

If you want it to look good on all devices(no black bar) you would need to check which device it is running on then update the size and position of your sprites accordingly.




回答2:


Its quite a commonly asked question.

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, 1334*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.

Regardless of scene size scale mode is usually best left at .aspectFill or .aspectFit, again depending on what you prefer and need (e.g cropping with aspectFill or black bars with aspectFit)

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



来源:https://stackoverflow.com/questions/43175389/scale-sprite-kit-game-for-all-devices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!