Game Development Reference
In-Depth Information
}
-(void) shootBulletFrom:(CGPoint)startPosition
velocity:(CGPoint)velocity
frameName:(NSString*)frameName
{
CCArray* bullets = batch.children;
CCNode* node = [bullets objectAtIndex:nextInactiveBullet];
NSAssert([node isKindOfClass:[Bullet class]], @"not a Bullet!");
Bullet* bullet = (Bullet*)node;
[bullet shootBulletFrom:startPosition velocity:velocity frameName:frameName];
nextInactiveBullet++;
if (nextInactiveBullet > = bullets.count)
{
nextInactiveBullet = 0;
}
}
@end
The shootBulletFrom method has changed the most, as you can see. It now takes
three parameters— startPosition , velocity , and frameName —instead of a
pointer to the Ship class. It then passes on these parameters to the Bullet class's
shootBulletFrom method, which I had to refactor as well. This is the new imple-
mentation that replaces the original shootBulletFrom method:
-(void) shootBulletFrom:(CGPoint)startPosition
velocity:(CGPoint)vel
frameName:(NSString*)frameName
{
self.velocity = vel;
self.position = startPosition;
self.visible = YES;
// change the bullet's texture by setting a different SpriteFrame to be displayed
CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache]←
spriteFrameByName:frameName];
Search Nedrilad ::




Custom Search