The CCDrawNode class
There are two ways to draw primitive shapes using the functionality provided by Cocos2d-x: one is using the various functions in CCDrawingPrimitives
and the other way is using the CCDrawNode
class. While the functions defined in CCDrawingPrimitives
offer abundant variety, they also incur a performance penalty. The CCDrawNode
class, on the other hand, provides just three different drawing functions and batches all its draw calls together to give much better performance. It also inherits from CCNode
and thus we can run a few common actions on it! So, we will be using CCDrawNode
to render our primitive shapes for this game.
Everything you saw in the preceding screenshot has been drawn using code—except for the score of course. All the main entities of our game, that is, the player, enemies, and power-ups, will inherit from CCDrawNode
as you will see shortly. If you're confused about how primitive drawing can yield the preceding results, the following section will make things...