Game Development Reference
In-Depth Information
The actual shooting code first checks whether the parent is visible, because if the par-
ent isn't visible, the code obviously shouldn't shoot. The BulletCache is what
shoots the bullet, using the bulletFrameName provided to the component and a
fixed velocity. For the start position, the component's position itself is irrelevant. In-
stead, the parent position and contentSize properties are used to calculate the cor-
rect starting position—in this case, at the left side of the enemy's sprite.
This bullet startPos works reasonably well for regular enemies but may need
tweaking for the boss enemy. I'll leave it up to you to add another property to this com-
ponent to set the bullet startPosition with. Alternatively, you could also create a
separate BossShootComponent and add this only to boss enemies to create more
complex shooting patterns. The same goes for StandardMoveComponents , which
for the boss might require hovering at a certain position at the right-hand side of the
Speaking of which, the interface for the StandardMoveComponent is pretty light-
#import < Foundation/Foundation.h>
#import "cocos2d.h"
@interface StandardMoveComponent : CCSprite
CGPoint velocity;
And the implementation doesn't do anything fancy either, as you can see in Listing
8-14 .
Listing 8-14. The Implementation of the StandardMoveComponent
#import "GameLayer.h"
Search Nedrilad ::

Custom Search