Kodeco Forums

How To Make A Game Like Color Switch with SpriteKit and Swift

Learn how to make a game like Color Switch using SpriteKit and Swift.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/790-how-to-make-a-game-like-color-switch-with-spritekit-and-swift

The zRotation approach is truly DRY Code, Awesome Tutorial!!

when i put the extension outside the closing curly brace of the class, as instructed

dieAndRestart()

was not recognised.
If I include that function within the extension

setupPlayerAndObstacles()

is not recognised

I noticed as the user keeps going up the number of nodes keeps piling up. There’s no code to remove the excess nodes as they go off the bottom of the screen. So I tried something like this…

  if (obstacles.count > 5) {
    obstacles.first?.removeFromParent()
    obstacles.removeFirst()
   }

That seemed like a good idea, but it doesn’t work. instead of just removing the offscreen obstacles below the player, as the player progresses, it seems to basically delete all of the obstacles, mostly, visible or not. I’m noticing that the add obstacle code is somehow hardwired to the count of obstacles, which is probably problematic… but I’m not seeing the solution initially… What did I do wrong?

actually, i further noticed that as objects keep being added, the position.y keeps increasing, and after a while, there would be an overflow… it really makes more sense to make a loop, moving the camera and player secretly down to the bottom, removing objects off screen, and placing new ones off screen above…

if i set Edge 3 then game is not working why ?

struct PhysicsCategory {
static let Player: UInt32 = 1
static let Obstacle: UInt32 = 2
static let Edge: UInt32 = 3
}

The individual values need to be powers of 2 because this isn’t an ‘Id number’, but a bit mask. If you aren’t familiar with bit masks, there is a link in that section to another Sprite Kit tutorial that has a good illustration.

So the int values should be 1, 2, 4, 8, 16 …

The reason 3 doesn’t work, is it isn’t a unique value, it’s saying 'this element belongs to both group 1 and group 2’ because 3 = 2 + 1

Hope that helps

1 Like

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