Game Development Reference
lustrates my point well. It doesn't contain much code, but even the smallest amount of
duplicated code increases the time you spend maintaining It.
The ccTouchBegan method takes the touch location and checks via the
CGRectContainsPoint whether the touch location is inside the spider sprite's
boundingBox . If so, it handles the touch and runs the code that lets the spider move
away quickly in one of four directions.
In summary, using a CCNode as a base class for your game objects makes a few things
more inconvenient at first glance. The benefits do become visible when you start creat-
ing larger projects, however, like when you're dealing with more than a dozen of
classes for game objects. It's okay if you prefer to subclass CCSprite for now. But
when you get more proficient—and more ambitious—please come back to this chapter
and try this approach. It leads to a better code structure and more clearly separated
boundaries and responsibilities of the individual game elements.
Curiously Cool CCNode Classes
Please remain seated as I walk you through a few more CCNode -derived classes that
fulfill very specific purposes. They are CCProgressTimer , CCParallaxNode ,
and CCMotionStreak .
In the ScenesAndLayers07 project, I've added a CCProgressTimer node to the
UserInterfaceLayer class. You can see how it cuts off chunks from a sprite in a
radial fashion in Figure 5-3 .