Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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: This CCNode class method is the one you should override in your classes derived from CCNode to customize drawing your nodes. It's important here not to call [super draw] or you will face unexpected behavior.

  • The visit method: This CCNode class method gives you more control as it calls the draw 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 from CCNode, is the one that gives you full control over the primitives because they are treated as nodes themselves.

The draw method presents a problem when there are...