(No. 00004) Implementing brick-hitting games for iOS (5): game scenarios
Create game scenario header files
Create a new GameScene class in Xcode, inherit from CCNode, and replace its header file with the following content:
# Import CCNode. h @ class Stick; @ interface GameScene: CCNode
// Read the rebound rod instance in the Level in GameScene @ property (atomic, strong) Stick * stickInGameScene; // @ property (nonatomic, assign) BOOL isStickShooting; // returns the current GameScene instance + (instancetype) sharedGameScene;-(CCPhysicsNode *) physicsWorld;-(void) addBall :( CCSprite *) ball;-(NSInteger) currentBallsCount; @ end
Some attributes and methods are added to obtain and set some necessary objects in the game scene, such as small balls and rebound sticks. because the physical collision must be handled in the scenario, the physical collision protocol is added and will be used later.
Implement game scenarios
Implement the initialization file in GameScene. m:
-(Void) didLoadFromCCB {// initialize the internal static variable sharedGameScene = self; // load the current Level node GameState * gameState = [GameState sharedInstance]; _ level = (Level *) [CCBReader load: gameState. currentLevel]; [self addChild: _ level]; _ level. zOrder = 50; // initialize the instance variable self. stickInGameScene = (Stick *) [self getChildByName: @ stick recursively: YES]; NSAssert (self. stickInGameScene, @ stickInGameScene must not nil); // initialize the score ratio _ scoreRatio = 1; // obtain the physical world object in the Level _ physicsWorld = (CCPhysicsNode *) [self getChildByName: @ physicsWorld recursively: YES]; NSAssert (_ physicsWorld, @ physicsWorld must not nil); // open the physical debugging display _ physicsWorld. debugDraw = YES; // sets the physical collision proxy _ physicsWorld. collisionDelegate = self; _ userInterface. zOrder = 100; _ msgLabel. zOrder = 101; self. userInteractionEnabled = YES; self. zOrder = 0; _ bils = [NSMutableArray array]; _ viewSize = [CCDirector shareddire]. viewSize ;}
The Code roughly does the following:
Create your own shared instances and add the current level scenario. In the following blog, we will describe the initialization rebound rod and the Z-order setting of each scenario in the physical world.