Chapter 6

Drawing with UIKit and Core Graphics

What You Will Learn In This Chapter:

  • Exploring the basics of the UIKit and Core Graphics drawing frameworks
  • Learning about the iOS drawing environment
  • Drawing shapes with UIBezierPath
  • Specifying colors with UIColor
  • Drawing shadows and gradients with Core Graphics
  • Working with images
  • Animating a game with CADisplayLink
  • Building a complete, animated, graphical game

In the first section of the book, you learned about the tools that you needed to get started building games for iOS. These included the Xcode programming environment, the C and Objective-C languages, and the Cocoa Foundation framework. Now that you have a solid foundation in the basics, you are ready to move on to the next level of tools. In this chapter, you will learn about some of the APIs that iOS provides for drawing graphics.

Introducing the Drawing Frameworks

There are two principal methods for drawing graphics in iOS. First, you can use the native drawing technologies in the UIKit and Core Graphics frameworks. These frameworks provide an object-oriented way to work with 2D graphics and images. You will be using these tools in this chapter to play with some samples and to build the example game, Blocker.

Blocker is a simple block-breaking game as you can see in Figure 6.1. The object of Blocker is to break all of the blocks at the top of the screen by hitting them with the ball. You must prevent the ball from going off the bottom of the screen by using the paddle. ...

Get Beginning iOS Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.