SpriteKit Level Designer – Part 2

UPDATE – I’d like to throw this tutorial up for discussion. The method I have shown below is something of an experiment that works, but it may not be the best way so in the interests of furthering knowledge I would be very interested to see what everyone thinks.

In the first part of this tutorial we had a very basic look at using the spritekit level designer and getting reference to a node in code. In this part we are going to look at loading nodes in from and .sks file. This could be useful for game levels etc.

Let’s continue where we left of last time (click here for the previous tutorial). The first thing to do is create another SpriteKit Scene file. Go to new file and in the “Resource” section select SpriteKit Scene File and name it “level1”

Screen Shot 2014-12-21 at 11.07.40

Once the new file has loaded in the editor drag out two Shape Nodes and place them somewhere around the the centre of the scene. Change the fill color on each of them to anything you want. Now, in the inspector, set their names to testNode2

spritekit level designer

Go to your GameScene.swift class and add the following method

There’s not much to this and a quick read through should make its intent fairly obvious. It simply loads the scene file and then enumerates the nodes and adds then to the current scene. Note that you need to remove the node from its parent (level1) and add it to the current scene.

Next you need to add the following line to the didMoveToView function

If you run the project now (use an iPad simulator, I’ll discuss why in another tutorial) you should see a screen like this

Screen Shot 2014-12-21 at 11.10.17

And that’s it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.