Game Development Reference
In-Depth Information
Now add the player sprite to the game scene. I decided to add it as a CCSprite*
member variable to the GameLayer class That's easier for now, and the game is
simple enough for everything to go into the same class. Generally, that's not the recom-
mended approach, so the projects in later chapters will create separate classes for indi-
vidual game components as a matter of good code design.
Listing 4-4 shows the addition of the CCSprite* member to the GameLayer header
Listing 4-4 . The CCSprite* Player Is Added as a Member Variable to the GameLayer
#import < Foundation/Foundation.h>
#import "cocos2d.h"
@interface GameLayer : CCLayer
CCSprite* player;
+(id) scene;
Listing 4-5 contains the code I've added to the init method to initialize the sprite, as-
sign it to the member variable, and position it at the bottom center of the screen. I've
also enabled accelerometer input
Listing 4-5 . Enabling Accelerometer Input and Creating and Positioning the Player
-(id) init
if ((self = [super init]))
CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
self.isAccelerometerEnabled = YES;
Search Nedrilad ::

Custom Search