(No. 00004) Implementing brick-hitting games for iOS (5): game scenarios

Source: Internet
Author: User

(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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.