SpriteKit Swift 3 Tutorial for Beginners

@boelaars @jkp Thanks, I clarified the instructions to specify to select “Create Groups”.

@henauker Thanks, I clarified the instructions on where to add the code for beginners.

@prady32 Good catch, fixed!

@arrow This is what I get for forced unwrapping, heh :stuck_out_tongue: I assumed the first/second physics body node would always be a SKSpriteNode, but seems sometimes it isn’t for some reason. I reproduced this and fixed it by using an if let statement; I’ve updated the tutorial and sample project. Thanks for the catch!

@rwenderlich Thank you so much for solving this. It was worth millions to me! Just got my motivation back on top again.

@jnbutler1815 Thanks for posting the code about how many monsters have been killed.

@knagle i also see this memory leak, about 1MB per loop. If you just run the game an leave it there dying/restarting you can see it quite easily in Instruments.

@rwenderlich any ideas?

@rwenderlich This is a really good tutorial. I do have a question, however.

Here is a M.W.E. and two StackOverflow related questions: Question 1, and http://stackoverflow.com/questions/41782820/swift-skspritekit-using-storyboards-uiviewcontroller-and-uibutton-to-set-in-g (sorry new users only get 2 links) using that M.W.E.

While getting your feedback on both would be great, right now question one is of more concern.

Suppose, rather than just starting the game with the GameViewController, one decides to use Main.storyboard to set up a menu, that allows one to set a difficulty and then transition to the GameViewController which brings up the GameScene.

In your tutorial, you programmatically make a SKView that, when a condition is met (30 monsters killed, or monster makes it past the screen) is shown.

In the M.W.E, how could one transition from the GameScene in GameViewController to the the UIView in the UIViewController (which has the label score)? It isn’t as straight forward (I don’t think), as showing a new view, and if one wants to pass information to the the new UIViewController (e.g. the score).

@knagle @gingerbeardman has one of you been able to fix the memory leak issue?

@jpaaquino To deallocate the scene we need to remove all nodes/actions from it.

In GameScene.swift After each presentation line:

self.view?.presentScene(gameOverScene, transition: reveal)

Add this:


And watch how the dealloc() will be called :wink:

Great tutorial Ray! Thanks so much.

I’m trying to add a few features to the resulting code.
I’m having trouble adding a background image. FPS drops a lot(at least in simulator).

This is what I’ve added:
let background = SKSpriteNode(imageNamed: "snow") //at start of GameScene class next to var monstersDestroyed = 0

at the start of override func didMove(to view: SKView) {
background.position = CGPoint(x: size.width/2, y: size.height/2)
background.zPosition = -1

Any thoughts?

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]