Game Development Reference
In-Depth Information
cause the Ship class has no access to the GameScene , I also needed to add the
singleton accessor sharedGameLayer to allow the ship to get to the CCS-
priteBatchNode , as shown in Listing 6-6 .
Listing 6-6. The GameScene Gets a CCSpriteBatchNode for Bullets and Accessors for
the Ship Class
static GameScene* sharedGameLayer;
+(GameScene*) sharedGameLayer
{
NSAssert(sharedGameLayer ! = nil, @" instance not yet initialized!");
return sharedGameLayer;
}
-(id) init
{
if ((self = [super init]))
{
sharedGameLayer = self;
. . .
CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"bullet.png"];
[self addChild:batch z:1 tag:GameSceneNodeTagBulletSpriteBatch];
}
return self;
}
-(void) dealloc
{
sharedGameLayer = nil;
}
-(CCSpriteBatchNode*) bulletSpriteBatch
{
CCNode* node = [self getChildByTag:GameSceneNodeTagBulletSpriteBatch];
NSAssert([node isKindOfClass:[CCSpriteBatchNode class]], @"not a SpriteBatch");
return (CCSpriteBatchNode*)node;
}
 
 
Search Nedrilad ::




Custom Search