2

I'm trying to get comfortable with Sprite Kit level editor. By default, there is one "gamescene.sks" file that's attached to "gamescene.swift".

If i'm making a "gameoverscene" or "playscene" for example, do I need to create both of them (.swift and .sks) if I want to work with my game in the level editor ?

Also, I'm interested in it's size management. I'm making a universal devices game. Should I change it's default size (1024x768) or do not bother ?

Also that scene canvas looks horizontal, should I change it if my game is a portrait-mode only ?

sangony
  • 11,636
  • 4
  • 39
  • 55
Burundanga
  • 668
  • 5
  • 15

1 Answers1

3

Short Answer. Yes.

Reason..

Every time you want to present or load an .sks file, You need to load it with a class like so

let doors = SKTransition.doorwayWithDuration(1.0)
        let archeryScene = GameScene(fileNamed: "GameScene")
        self.view?.presentScene(archeryScene, transition: doors)

If you look a the constant loads the file with a class

MyScene(fileNamed: "MyScene")

So yeah you do need a .swift file for each .sks file.

For more info on .sks files look here.

Techotopia - An iOS 8 Swift Sprite Kit Level Editor Game Tutorial

Also when I use the Spritekit Level Editor, I usually set the Scene size to 960 x 640 to support the smallest iPhone. Alsong as you have @1x, @2x, @3x and possibly @1x~iPad and @2x~iPad, Everything will be fine. Just to be sure in the ViewDidLoad or the initWithSize(CGSize) to add self.scaleMode = .AspectFill. You can set it to what ever it may be. Your options are,

SKSceneScaleMode.Fill

Each axis of the scene is scaled independently so that each axis in the scene exactly maps to the length of that axis in the view.

SKSceneScaleMode.ResizeFill

The scene is not scaled to match the view. Instead, the scene is automatically resized so that its dimensions always matches those of the view.

SKSceneScaleMode.AspectFit

The scaling factor of each dimension is calculated and the smaller of the two is chosen. Each axis of the scene is scaled by the same scaling factor. This guarantees that the entire scene is visible, but may require letterboxing in the view.

SKSceneScaleMode.AspectFill

The scaling factor of each dimension is calculated and the larger of the two is chosen. Each axis of the scene is scaled by the same scaling factor. This guarantees that the entire area of the view is filled, but may cause parts of the scene to be cropped.

(Credits to @epicbyte - Dealing with different iOS device resolutions in SpriteKit)

Community
  • 1
  • 1
Jesse Onolemen
  • 1,277
  • 1
  • 15
  • 32
  • Wow! Thank you so much! That is clearly what I needed to know about it! One more thing: do I really need `@1x~iPad` and `@2x~iPad` if my device is universal? I thought it's for device specific games and for universal devices I need just (at)1,2,3? – Burundanga Mar 13 '15 at 16:36
  • You dont need it but if you want best results then I would recommend it. – Jesse Onolemen Mar 13 '15 at 18:33
  • I tried this and to be honest I don't understand where to put your code. I'm making a pause scene in level editor. So I have .swift file for a main scene, and .sks + .swift for a pause scene. Where should I put that code? Also, I thought that to apply .sks file I need `NSKeyedUnarchiver`, don't I? It's just, I'm looking at default code in `GameViewController` for applying .sks file to GameScene.swift and it don't look like yours. – Burundanga Mar 18 '15 at 21:20
  • Every time that you want to load the scene. It worked for me. I might double check it again. I believe the code in the GameViewController, Setups the code needed to use .sks files and does not need to be implemented later on. Try to see if that code works :) – Jesse Onolemen Mar 19 '15 at 17:46
  • No, sadly, it's not working at all. I put your code in pauseScene.swift file and Xcode says "use of unresolved identifier" for "PauseScene" and "self". I also tried to do like this `class: PlayScene {your code}`. Then it don't likes only "self". I'm definitely doing something wrong but I can't understand what. I also tried that answer: [link](http://stackoverflow.com/questions/28685733/how-do-i-link-a-sks-file-to-a-swift-file-in-spritekit?rq=1) In that case Xcode isn't showing any errors but simulation is crushing every time I hit pause button. – Burundanga Mar 20 '15 at 19:39
  • Okay it worked for me well before. I'm, sorry to hear that. I will try some other things and feed back. I guess that It might have changed. I pulled it straight from a book I saw but that came out in the early stages of swift and spritekit. – Jesse Onolemen Mar 21 '15 at 06:40
  • Also here is where i got it from, Sorry it's not a book mistake :D - http://www.techotopia.com/index.php/An_iOS_8_Swift_Sprite_Kit_Level_Editor_Game_Tutorial – Jesse Onolemen Mar 21 '15 at 06:42
  • Yeah, I have that book too and tried to implement their suggestions. To be honest I have a feeling that I made something wrong anywhere else. But it looks like a simple thing and I don't even know where could I make a mistake. I Will read that chapter again now, maybe I missed something :D – Burundanga Mar 21 '15 at 07:23
  • I've made another [question](http://stackoverflow.com/questions/29181419/scene-created-in-sprite-kit-level-editor-is-not-working) specifically for that problem and put there all the code I have for this with explanation how I end like this. Maybe it would be easier to understand the problem with it. – Burundanga Mar 21 '15 at 10:03