I already read tons of stuff but im still having a lot of problems with it.
First i went for the correct Scalemode with in my understading is AspectFit. Here the post i read:
Difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill?
But even so another post tells to use ResizeFill:
Dealing with different iOS device resolutions in SpriteKit
The problem with that is that the SKScene on Ipad only get 1/10 of the screen, it looks like i need to make 2 separate SKScene, one for Ipads and another for Iphone.
But still for Ipad i get 2 black lines on top and bottom of the screen. Then i saw this post:
viewWillLayoutSubviews in Swift
What im using to change views is this code:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let scene = Level(fileNamed: "Level")
scene!.scaleMode = .AspectFit
let transition = SKTransition.fadeWithDuration(0.5)
self.view?.presentScene(scene!, transition: transition)
}
What are the correct practices when using SKScene for an universal app? Im already using Atlas to get @x1, @x2 and @3 images. My SKScene size is 480x320, from what i read is the best size to build an universal app.
I have recently tried converting my iPad app to a universal, and I can shed some light on this.
There are several sizes you need to take into account. First, the view
size. This is the SKView instance you order to present the SKScene. Usually, this view has a size equal to the size of [UIScreen mainScreen].size
:
Your SKScene
also has a size property which indicates the size of its viewport. This is the size (or the resolution, if you will) in points at which SpriteKit renders the scene.
The last thing to discuss is scaleMode which is how the SKView frames the rendered scene inside itself. You can think of this as a UIImageView framing a UIImage inside itself, only we have fewer options for SKScene. So if you have a view of 576*320 and a SKScene with size 1024*768 the result is a horizontally stretched image.
Note that when adding an SKScene to an SKView using -presentScene:
, the passed scene's size is resized to the view's size.
Depending on your game, you can have 2 .sks files (one for iPhone, one for iPad). Set the size of the root object in each file (the SKScene node) to the size of the device that you're targeting. That's what I'll probably end up doing, anyway.