0

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.

Community
  • 1
  • 1
Gusfat
  • 111
  • 11

1 Answers1

2

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:

  • iPad | 1024*768
  • iPad Pro | 1366*1024
  • iPhone 4" | 320*576
  • iPhone 4.7" | 375*667
  • iPhone 5.5" | 414*736

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.

TL;DR

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.

CloakedEddy
  • 1,965
  • 15
  • 27
  • I see. Thats a nice approach. I though about using 2 SKScene but i didn't know if you could. "So if you have a view of 576*320 and a SKScene with size 1024*768 the result is a horizontally stretched image." Yeah that was my biggest problem. What i end doing in the end (for now at least) is using AspectFill and adjusting the background for Iphone and Ipad. If you get Plant vs Zombies for Iphone and Ipad you can see that the iPhone version has a bigger background. I got the same results with my tests. Anyway i think the 2 scenes are a nice way to work too. What are you doing? Different sizes? – Gusfat Sep 18 '15 at 22:47
  • Like the Ipad SKScene is 900x800 (example) and the Iphone 400x200 (example too)? – Gusfat Sep 18 '15 at 22:48
  • I would not use two different `SKScene` subclasses, but rather init your subclass from a different .sks file depending on screen size. That way, you don't have to duplicate your logic. In addition, you can have some screen-dependent CGPoints inside your subclass as well. – CloakedEddy Sep 24 '15 at 09:10
  • Yeah thats what i done =) I just had to change the physics body of the nodes due to the size of the sks but rather than that was perfect. Cheers! – Gusfat Sep 24 '15 at 18:27