Creating D-Pad Controls for an iOS Game in Swift & SpriteKit

This is part of a free course that teaches game design and the Swift programming language. It contains examples from a real game I created called ForeverMaze. The full course includes the source code for the whole game.

Learn how to control a character for your game with “D-Pad.” This tutorial will show you how to use Swift to create a simple but powerful control structure.

Download Direction.swift

What Is a D-Pad?

D-PadA “D-Pad” is short for “directional pad,” one of the most common game controller input styles.

Of course, modern mobile devices do not have physical buttons. So we need to create our own D-Pad implementation. In ForeverMaze, the player simply presses somewhere on screen and then drags his finger around. The original press acts as the center point of the D-Pad, and the distance he moves from that center point indicates the direction to move in.

I found that this was a very simple and intuitive way to control characters in ForeverMaze. In my testing, every single user was able to figure it out within seconds. The only trick with implementation was the fact that the game is 2.5D, meaning everything is rotated by 45 degrees. Let’s see how that works…

Detecting User Input in SpriteKit

Your SKScene subclass will need to detect the user input. This means simply overriding methods like touchesBegan . From there,  we simply keep track of the touches. If at any time we want to know what direction the user is facing, we can access the variable self.dPadDirection  … which will return nil  if the user is not currently trying to move.

That’s it! Quite simple, really.

If you enjoyed this post, why not enroll in the free course? It contains hours of video content, source code downloads, examples and more. I cover many different intermediate and advanced topics for creating a real-time game in Swift with SpriteKit and Firebase. You can check out the complete game at

Leave A Comment

You must be logged in to post a comment.

Back to Top