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
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Setting the LED Player Indicator

One last minor thing. You can control the state of the LED lights on the controller. These lights are there to indicate which player is controlled by that controller.

In toggleHardwareController, right after this line:

self.controller = [GCController controllers][0];

Add this line:

self.controller.playerIndex = 0;

This will set the value on the controller for the playerIndex to 0. This does two things, it should set the LED indicator on the controller (on the SteelSeries it didn’t work consistently for me, but it worked fine on the MOGA).

Secondarily, it will remember the playerIndex for that controller. So, if you disconnect that controller, then reconnect it again later, that hardware will still identify itself to the GameController framework as playerIndex 0. If you want to clear the playerIndex (and I recommend that you do when you are finished with a controller), you set the playerIndex value to GCControllerPlayerIndexUnset. This constant is the default value when a controller is connected.

Build and run, and check out the LED!

Where To Go From Here?

You can download the final project here.

Now that you understand hardware controllers, you should add support into your games! There are more than a hundred games now that support hardware controllers, with hopefully many more to come.

To learn more about hardware controllers, check out Apple’s Game Controller Programming Guide.

I hope you enjoyed this tutorial, and if you have any questions or comments, please join the forum discussion below!

Jake Gundersen

Contributors

Jake Gundersen

Author

Over 300 content creators. Join our team.