Game Development Reference
In-Depth Information
In fact screenRect is useful to other classes, so it may be a good idea to move it to
where you can access it from other classes. One way to do that is to add a property to
the GameLayer class. You add the same init code as in Listing 8-5 to the
GameLayer init method, and a method to return the static variable with the same
static CGRect screenRect;
-(CGRect) screenRect
return screenRect;
And to the interface of GameLayer add the readonly property declaration for
screenRect :
@property (readonly) CGRect screenRect;
By the way, whether screenRect is a static variable or an instance variable of the
GameLayer class makes no difference in this instance. You can now import the
GameLayer.h header file in another class and access screenRect via:
CGRect rect = [GameLayer sharedGameLayer].screenRect;
The InputLayer can now use the new BulletCache class and use it to shoot the
player's bullets. The bullet properties, such as starting position, velocity, and the sprite
frame to use, are now passed by the shooting code in the update method of the In-
putLayer in Listing 8-6 .
Listing 8-6. The InputLayer Class Is Modified to Let the BulletCache Class Handle All
the Action
. . .
-(void) update:(ccTime)delta
totalTime + = delta;
Search Nedrilad ::

Custom Search