iOS 7 Game Controller Tutorial

Learn how to add control your games with a joystick in this iOS 7 game controller tutorial! By Jake Gundersen.

Leave a rating/review
Save for later
Share

iOS 7 introduced official support for hardware game controllers. This is great because some games are particularly well suited for hardware game controllers – imagine Mario with a touch interface!

It’s also great because now that it’s official, you can support a variety of game controllers just by implementing a single API.

On top of that, Apple has provided prospective controller manufacturers with specific requirements in order to be compatible with iOS. Apple isn’t just letting just any yahoo make a hardware controller for iOS!

In this tutorial, you will add hardware game controller support into a simple platformer game like Mario, made with Sprite Kit.

This tutorial has the following prerequisites:

  • Some basic Sprite Kit experience. If you are new to Sprite Kit, I recommend checking out our Sprite Kit Tutorial for Beginners first.
  • A hardware iOS game controller. There’s no way to test game controllers in the simulator, so you’ll need a hardware iOS game controller for testing. If you’re wondering which one to get, I recommend picking up the Stratus SteelSeries Wireless Gaming Controller.
  • Review starter game (optional). As I mentioned, you will be adding game controller support into a simple Sprite Kit platformer game like Mario. If you’d like to learn how to make this game, we have a tutorial for that.

Grab your game pad and let’s get started!

Supported Game Controller Types

There are exactly three game controller types supported by the Game Controller framework, as specified in Game Controller Programming Guide:

1) A standard form-fitting controller

The form-fitting controller encases the iPhone within the controller, connecting via the lightning connector.

At the time of writing this article, there is only one of these types of controllers available – Logitech’s Powershell controller.

Logitech Powershell

This type of controller supports the “standard” controller profile, which means it has the following inputs:

  • Direction Pad (always on the left)
  • 4 buttons A, B, X, Y (always on the right>
  • 2 shoulder buttons, one on the left and one on the right
  • Pause button

2) An extended form-fitting controller

The second type of controller is also form-fitting, but it contains some extra buttons so is considered “extended.”

At the time of writing this article, there is only one of these types of controllers available – MOGA’s ACE Power controller.

MOGA

Note that an extended controller like this one contains some additional buttons:

  • Two thumbsticks, one left and one right
  • Additional pair of shoulder buttons/triggers

3) An extended wireless controller

The final controller type is the external/bluetooth controller, such as Stratus’s SteelSeries controller.

This supports the extended gamepad (I believe that external controllers are all required to support the extended profile, that’s my impression from the WWDC videos in any case).

SteelSeries

The external controllers connect via bluetooth and must first be paired to the device in order work. Once paired, any time the controller is powered on it will connect via bluetooth to the same device.

The full collection

Here’s an image of my current hardware collection:

Controllers

In this image:

  • Upper-middle: The iCade: A legacy game controller that came out before the iOS 7 game controller API was released.
  • Upper-left: Stratus SteelSeries A extended wireless controller.
  • Upper right: Logitech Powershell: A standard form-fitting controller.
  • Lower left: MOGA’s ACE Power controller: An extended form-fitting controller.
  • Lower right: Xbox 360 controller: Don’t get excited, these don’t work on iOS! :] I just included it in the picture here for size comparison purposes.

Common characteristics

Beyond specifying the controller types, Apple specifies certain characteristics that all controllers must satisfy. These are intended to provide a consistent, high quality experience when using a hardware controller with an iOS device.

If you would like to have a complete picture of the benefits of Apple’s requirements, I suggest watching the video on hardware controllers from WWDC 2013. But, let me just mention a few things:

  1. All buttons are pressure sensitive
  2. Thumb sticks must have no dead zones or drift
  3. Controllers must have LED indicators that indicate player number
  4. A, B, X, and Y buttons always have the same color

Game Controller Design Considerations

Apple has a few requirements that you must satisfy in order to submit an app that supports a hardware controller. The first, and most important, is that you must not require a hardware controller. Your game must be playable with standard touch/tilt controls.

This means that you have to put thought into how you are going to implement your control scheme. An Extended Gamepad has a total of 13 controls, good luck fitting all of those controls on a touch screen!

Don’t do this!

Don't do this!

Because of these issues, many games provide completely different controls schemes on a hardware controller versus the touch screen.

For example, LEGO Star Wars uses the hardware controller to move around the player in 3D space, but if you use the touch screen, you simply touch on the screen where you want the player to go, and he will move to that spot.

You will have to be creative to make a game that takes advantage of the hardware controller, but still plays well with touch screen controls. You don’t want to design for the hardware and then add touch screen controls as an after thought. Realistically, most of your users will be playing your game via the touch screen, so you want both experiences to yield praise and good reviews.

Getting Started

As I mentioned earlier, in this tutorial you will be adding game controller support to the Super Koalio game from our Sprite Kit platformer game tutorial.

In the original tutorial, Super Koalio has a very simple control scheme. Tapping on the left side of the screen walks forward (forward only) and tapping on the right side of the screen jumps.

However, I have created a modified version of the starter project that contains a more complete set of controls and on screen buttons and joystick.

Download the starter project, build and run, and try out the new control scheme.

Final Controls

The new control scheme uses an analog stick (provided on github by the sneaky narwal – you can get that code here), and two buttons:

  • Dash button: This enables Koalio to reach a much higher top speed. You won’t need this in the hardware controller because the analog stick will enable you to move Koalio at a much wider variety of speeds, however you need a solution for touch players, hence this button. Pressing dash makes the Koala change size/shape and shades his image darker to give visual feedback of his state.
  • Jump button: The jump buttons is simple, but often you want to hold dash and press jump and the same time. Because a touch point is a single point rather than the entire surface area of your thumb, you need something else in order to use both buttons. In my scheme, if you press the B button, it stays pressed until you release that touch. That way, you can start on B and slide onto and off of the A button and the B button stays pressed.

Note that the control layer is a separate class called HUDNode. The hardware controller will communicate with the HUD.

Jake Gundersen

Contributors

Jake Gundersen

Author

Over 300 content creators. Join our team.