Game Development Reference
In-Depth Information
ers to it. The only logic left for programming the switching of weapons is simply when
to deactivate which components.
What's more, you can reuse components in other games where they make sense, just by
adding them to the new project. There should be no need to modify the component
class behavior, therefore components are great for writing reusable code and are a
standard mechanism in many, many game engines. To learn more about game compon-
ents, see this blog post on my web site:
prefer-composition-inheritance .
Look at the StandardShootComponent 's source code, starting with the header
#import < Foundation/Foundation.h>
#import "cocos2d.h"
@interface StandardShootComponent : CCSprite
float updateCount;
float shootFrequency;
NSString* bulletFrameName;
@property (nonatomic) float shootFrequency;
@property (nonatomic) NSString* bulletFrameName;
There's one notable thing about this class. The StandardShootComponent inher-
its from CCSprite , even though it doesn't use any texture, nor does it need to be dis-
played on screen in any way. That's a workaround because all Enemy objects are ad-
ded to a CCSpriteBatchNode , which can contain only CCSprite- based objects.
This also extends to any child node of the Enemy class; thus, the Stand-
ardShootComponent needs to inherit from CCSprite to satisfy the requirement
of the CCSpriteBatchNode .
The implementation of the StandardShootComponent is shown in Listing 8-13 .
Search Nedrilad ::

Custom Search