We assume that youre a reasonably capable programmer, and that you know at least a little bit about developing for iOS: what Xcode is and how to get around in it, how to use the iOS Simulator, and the basics of the Swift programming language. We also assume you know how to use an iOS device. We dont assume any existing knowledge of game development on any platform, but were guessing that youre reading this book with a vague idea about the kind of game youd like to make.
This book isnt based on any particular genre of gamesyoull find the recipes in it applicable to all kinds of games, though some will suit some genres more than others.
Organization of This Book
Each chapter of this book contains recipes : short solutions to common problems found in game development. The book is designed to be read in any order; you dont need to read it cover-to-cover, and you dont need to read any chapter from start to finish. (Of course, we encourage doing that, because youll probably pick up on stuff you didnt realize you wanted to know.)
Each recipe is structured like this: the problem being addressed is presented, followed by the solution , which explains the technique of solving the problem (or implementing the feature, and so on). Following the solution, the recipe contains a discussion that goes into more detail on the solution, which gives you more information about what the solution does, other things to watch out for, and other useful knowledge.
Here is a concise breakdown of the material each chapter covers:
This chapter discusses different ways to design the architecture and code layout of your game, how to work with timers in a variety of ways, and how blocks work in iOS. Youll also learn how to schedule work to be performed in the future using blocks and operation queues, and how to add unit tests to your project.This chapter focuses on interface design and working with UIKit, the built-in system for displaying user interface graphics. In addition to providing common objects like buttons and text fields, UIKit can be customized to suit your needsfor some kinds of games, UIKit might be the only graphical tool youll need.In this chapter, youll learn how to get input from the user so that you can apply it to your game. This includes touching the screen, detecting different types of gestures (such as tapping, swiping, and pinching), as well as other kinds of input like the users current position on the planet, or motion information from the variety of built-in sensors in the device.This chapter discusses how to work with sound effects and music. Youll learn how to load and play audio files, how to work with the users built-in music library, and how to make your games sound work well when the user wants to listen to his or her music while playing your game.This chapter is all about storing information for later use. The information that games need to save ranges from the very small (such as high scores), to medium (saved games), all the way up to very large (collections of game assets). In this chapter, youll learn about the many different ways that information can be stored and accessed, and which of these is best suited for what you want to do.This chapter discusses Sprite Kit, the 2D graphics system built into iOS. Sprite Kit is both powerful and very easy to use; in this chapter, youll learn how to create a scene, how to animate sprites, and how to work with textures and images. This chapter also provides you with info you can use to brush up on your 2D math skills.In this chapter, youll learn how to use the two-dimensional physics simulation thats provided as part of Sprite Kit. Physics simulation is a great way to make your games movements feel more realistic, and you can use it to get a lot of great-feeling game for very little programmer effort. Youll learn how to work with physics bodies, joints, and forces, as well as how to take user input and make it control your games physical simulation.This chapter and the two that follow it provide a tutorial on OpenGL ES 2, the 3D graphics system used on iOS. These three chapters follow a slightly different structure than the rest of the book, because its not quite as easy to explain parts of OpenGL in isolation. Instead, these chapters follow a more linear approach, and we recommend that you read the recipes in order so that you can get the best use out of them. introduces the basics of OpenGL, and shows you how to draw simple shapes on the screen; at the same time, the math behind the graphics is explained.This chapter is designed to follow on from the previous, and discusses more advanced techniques in 3D graphics. Youll learn how to load a 3D object from a file, how to animate objects, and how to make a camera that moves around in 3D space.This chapter follows on from the previous two, and focuses on shaders, which give you a tremendous amount of control over how objects in your game look. Youll learn how to write shader code, how to create different shading effects (including diffuse and specular lighting, cartoon shading, and more), and how to make objects transparent.This chapter covers Scene Kit, Apples new 3D framework. It has recipes for showing 3D objects with Scene Kit; working with cameras, lights, and textures; and using physics in 3D.This chapter discusses how to make objects in your game behave on their own, and react to the player. Youll learn how to make one object chase another, how to make objects flee from something, and how to work out a path from one point to another while avoiding obstacles.In this chapter, youll learn about Game Center, the social network and match-making system built into iOS. Youll learn how to get information about the players profile, as well as let players connect to their friends. On top of this, youll also learn how to connect to nearby devices using Bluetooth. Finally, youll learn how to share text, pictures, and other content to social media sites like Twitter and Facebook.This chapter discusses the things that players can connect to their device: external displays, like televisions and monitors, and game controllers that provide additional input methods like thumbsticks and physical buttons. Youll learn how to detect, use, and design your game to take advantage of additional hardware where its present.The last chapter of the book looks at improving your games performance and stability. Youll learn how to take advantage of advanced Xcode debugging features, how to use compressed textures to save memory, and how to make your game load faster.