Chapter 6. 2D Graphics and SpriteKit

Just about every game out there incorporates 2D graphics on some level. Even the most sophisticated 3D games use 2D elements, such as in the menu or in the in-game interface.

Creating a game that limits itself to 2D graphics is also a good way to keep your game simple. 2D is simpler than 3D, and you’ll end up with an easier-to-manage game, in terms of both gameplay and graphics. Puzzle games, for example, are a category of game that typically use 2D graphics rather than more complex 3D graphics.

2D is simpler for a number of reasons: you don’t need to worry about how objects are going to look from multiple angles, you don’t need to worry as much about lighting, and it’s often simpler to create a great-looking scene with 2D images than it is to create a 3D version of the same scene.

iOS comes with a system for creating 2D graphics, called SpriteKit. SpriteKit takes care of low-level graphics tasks like creating OpenGL contexts and managing textures, allowing you to focus on game-related tasks like showing your game’s sprites on the screen.

Note

SpriteKit was introduced in iOS 7, and is available on both iOS and OS X. The API for SpriteKit is the same on both platforms, which makes porting your game from one platform to the other easier.

In this chapter, you’ll learn how to work with SpriteKit to display your game’s graphics.

6.1 Getting Familiar with 2D Math

When you’re working with 2D graphics, it’s important to know at least a little bit ...

Get iOS Swift Game Development Cookbook, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.