Now that the bike and walls are fleshed out, we turn our attention to the control buttons. As we have mentioned before, we are optimizing our graphics, so we actually only have a single black and white button to use for all the control buttons. Let's look at the class header first.
#import <Foundation/Foundation.h> #import "cocos2d.h" #import "CLDefinitions.h" #import "CLBike.h" @interface CLButton : CCSprite <CCTargetedTouchDelegate> { BOOL isLeft; // Is this a left turn button? CLBike *parentBike; // Bike the button controls CLPlayfieldLayer *myPlayfield; // main game layer } +(id) buttonForBike:(CLBike*)thisBike asPlayerNo:(NSInteger)playerNo isLeft:(BOOL)isLeftButton onLayer:(CLPlayfieldLayer*)thisLayer; @end
Here we have kept references to both myPlayfield
and the parentBike
. The variable myPlayfield
references the main playfield layer of our game. The
parentBike
is the bike that will...