Game Development Reference
CCNode* node = [self getChildByTag:GameSceneNodeTagBulletCache];
NSAssert([node isKindOfClass:[BulletCache class]], @"not a BulletCache");
Finally, this is the refactored GameLayer interface with the changes highlighted.
Most notably a @class forward for the BulletCache class was added, and both de-
faultShip and bulletCache accessor methods are declared as properties, so
from now on you can alternatively access them with dot notation.
. . .
@interface GameLayer : CCLayer
@property (readonly) Ship* defaultShip;
@property (readonly) BulletCache* bulletCache;
For the new BulletCache class, I decided to keep the CCSpriteBatchNode in a
member variable instead of using the CCNode getChildByTag method every time
you need the sprite batch object. It's a minor performance optimization. Because you'll
be adding the BulletCache class as child to the GameLayer , you can simply add
the sprite batch node to the BulletCache class.
Note There's little harm in increasing the depth of the scene hierarchy by
adding an in-between CCNode like BulletCache . If you're concerned about
scene hierarchy depth, the alternative would be to add the sprite batch node to
the GameLayer class as usual and use an accessor method to get to the sprite