Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite Kit Scene Editor GameScene.sks scene width and height

I'm using the spritekit scene builder to build my scene (aka the GameScene.sks file when you create the project in xcode 7 ios9). SpriteKit only uses pixel values when setting the screen height and width. My question is this:

If I set the pixels values to that of an iphone 6, will the game be too small for ipad and iphone 6+? Why is there no option to fit the device screen? What should I do to avoid this?

like image 642
Minimi Avatar asked Nov 28 '15 05:11

Minimi


1 Answers

Pixel density

First of all the size of the Scene is defined in Points not Pixels.

Let's see how the devices that support iOS 9 deal with this:

  • 1 point = 1x1 pixel: iPad 2, iPad mini
  • 1 point = 2x2 pixels: iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6s, iPad mini 2, iPad mini 3, iPad mini 4, iPad 3, iPad 4, iPad Air, iPad Air 2, iPad Pro, iPod touch 5, iPod touch 6
  • 1 point = 3x3 pixels: iPhone 6 Plus, iPhone 6s Plus

This allow you to specify a size that is automatically converted for the pixel density of a particular device.

Screen size

There are several screen sizes available on the iPhone/iPad supported by iOS 9.

With SpriteKit you can easily face this problem setting the scaleMode property of your Scene.

You can chose among 4 options:

  • Fill: Scale the SKScene to fill the entire SKView.
  • AspectFill: Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a different aspect ratio.
  • AspectFit: Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if the view has a different aspect ratio.
  • ResizeFill: Modify the SKScene's actual size to exactly match the SKView.

You probably want to set AspectFill but it really depends on your game.

To set the property open GameViewController.swift (or .m if you use Objective-C), in viewDidLoad you'll find this line. Just change it to mach your preference.

/* Set the scale mode to scale to fit the window */
gameScene.scaleMode = .AspectFill
like image 184
Luca Angeletti Avatar answered Nov 14 '22 22:11

Luca Angeletti