Game Development Reference
In-Depth Information
Abstracting the UI
In the previous example, we looked at the basics of creating a frame-by-frame animation. We looked
how we can use the class CADisplayLink in conjunction with the existing event loop to call a task
where we can implement our animation. We animated a single image around the screen based on
user input. That was a very simple example. I left out a number of practical considerations so we
could focus on the basic idea of creating animations in this way. In this section, we will do a little
refactoring in order to better support more complicated games. Figure 5-7 shows the example we
will be building.
Figure 5-7. Abstracted UI
In Figure 5-7 , we see some differences from the first example. The first thing to note is that the play
area of the game does not take up the full screen. The slider at the bottom of the screen changes
the size of the play area without changing how the game plays. There is also a second item on
the screen, an asteroid. Asteroids are created every 10 seconds and start at the top of the screen,
moving straight down. If an asteroid collides with the spaceship, the spaceship resets to the center
of the screen and the asteroid is removed. The object of this simple game is to avoid the incoming
asteroids.
 
Search WWH ::




Custom Search