Drawing and coloring
Usually, you will be working with sprites, nodes, and other high-level objects, but maybe sometimes you will want to draw some geometric primitives such as lines, circles, or squares. In our case, we're going to use them to represent our scientist's life bar.
Fortunately, Cocos2d allows us to perform these tasks easily by using any of these three options:
- The
draw
method: ThisCCNode
class method is the one you should override in your classes derived fromCCNode
to customize drawing your nodes. It's important here not to call[super draw]
or you will face unexpected behavior. - The
visit
method: ThisCCNode
class method gives you more control as it calls thedraw
method of the node and its children in the order they were added to it, taking into account the specified z-orders. CCDrawNode
: This class, derived fromCCNode
, is the one that gives you full control over the primitives because they are treated as nodes themselves.
The draw
method presents a problem...