Devlog #10: Game States

In this episode I introduce quite a few new things, including damage and health, game states with GameplayKit and fragment shader with SpriteKit.

Devlog #10: Game States
Johan Steen
by Johan Steen

In this episode I introduce quite a few new things, including damage and health, game states with GameplayKit, fragment shader with SpriteKit and I also refactored many parts of the code using more elegant Swift functionality.

Game States

I spent quite a lot of time to implement game states which makes quite a difference as it becomes more of a complete game than just a prototype level as previously. With game states the game now have

  • A game over state when the player runs out of lives.
  • A level completed state. That also comes with switching to a new level after completion.
  • A game completed state.
  • And also a respawn state for the player craft when all health is gone.
  • A state for being at the home screen / main menu.
  • And a pause state.

Damage and Health

Every entity can now use a health component and a damage component to track a their health property, so they don't just immediately die when they are hit. The damage property determines how much damage an entity deals. That allows for having different strengths for different bullet types.


GameplayKit Entity Component System

As the codebase keeps growing in complexity, I've started documenting the inner workings in a diagram. This has turned out to be really helpful to quickly recollect how things are set up. Highly recommended.

Fragment shader

I implemented a fragment shader to handle color changes when entities gets hit. As SpriteKit's own color blend is multiply based it can not flash to white, which I wanted. With a custom shader it now works as I expect it to work.

LunaX Engine

The game also have moved on from working title to a final title. LunaX Engine is the name of the game.

Game Devlog

This is the 10th episode of my devlog following the progress of my indie game, which is a top down shoot'em up, that I am coding in Swift on top of the SpriteKit and GameplayKit frameworks.


Discuss this article

The conversation has just started. Comments? Thoughts?

If you'd like to discuss any of the topics covered in this article, then head over and hang out on Discord.

You can also get in touch with me, and keep up with what I'm up to, on Twitter or Mastodon.

Sign up to the newsletter to get occasional emails about my game development.