Game Development Reference
In-Depth Information
for (CCNode* node in self.children)
if ([node isKindOfClass:[HealthbarComponent class]])
HealthbarComponent* healthbar = (HealthbarComponent*)node;
[healthbar reset];
You can now run the app and wait for a boss to appear. Each boss will have a red
healthbar on top that decreases in width the more bullets it's hit with.
Creating a complete and polished game is quite an effort—one that involves a lot of re-
factoring, changing working code to improve its design and to allow for more features
existing in harmony with each other.
In this chapter, you learned the value of classes like BulletCache and
EnemyCache , which manage all instances of certain classes so that you have easy ac-
cess to them from one central point. And pooling objects together helps improve per-
By using component classes and cocos2d's node hierarchy to your advantage, you can
create plug-and-play classes with very specific functionality. This helps you construct
your game objects using composition rather than inheritance. It's a much more flexible
way to write game logic code and leads to better code reuse.
Finally, you learned how to shoot enemies and how the BulletCache and
EnemyCache classes help perform such tasks in a straightforward manner. And the
HealthbarComponent provided the perfect example of the component system at
The game to this point leaves a couple things open for you to build on. First and fore-
most, the player doesn't get hit yet. And you might want to add a healthbar to the cruis-
er monster and write specialized move and shoot components for the boss monster's
Search Nedrilad ::

Custom Search