(no.00004) iOS implementation play brick Game (v): Game Scene class

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Create a game scene class header file

Create a new Gamescene class in Xcode, inherit from Ccnode, and replace its header file with the following:

#import "CCNode.h"  @class Stick; @interface gamescene : ccnode <ccphysicscollisiondelegate>//Read The example of rebound stick in level Gamescene@property(Atomic,Strong) Stick *stickingamescene;//@property(nonatomic,Assign)BOOLisstickshooting;//Returns Gamescene current instance+ (Instancetype) sharedgamescene;-(ccphysicsnode*) physicsworld;-(void) Addball: (ccsprite*) ball;-(Nsinteger) Currentballscount;@end

Some of the properties and methods are added to get and set the necessary objects in the game scene, such as small balls and bounce sticks. Because physical collisions need to be handled in the scene, a physical collision protocol is added, which we'll use later.

Implement the game scene class

To implement the initialization file in GAMESCENE.M:

-(void) didloadfromccb{//Initialize internal static variablesSharedgamescene = Self;//Load current level nodeGameState *gamestate = [GameState sharedinstance]; _level = (level*) [Ccbreader load:gamestate. CurrentLevel]; [ SelfAddchild:_level]; _level. ZOrder= -;//Initialize the bounce Stick instance variable in Gamescene     Self. Stickingamescene= (stick*) [ Selfgetchildbyname:@"Stick"Recursively:YES]; Nsassert ( Self. Stickingamescene, @"Stickingamescene must not nil");//Initialize score ratio_scoreratio =1;//Get Physical World object in level_physicsworld = (ccphysicsnode*) [ Selfgetchildbyname:@"Physicsworld"Recursively:YES]; Nsassert (_physicsworld, @"Physicsworld must not nil");//Turn on physical debug display_physicsworld. Debugdraw=YES;//Set up physical collision agent_physicsworld. Collisiondelegate= Self; _userinterface. ZOrder= -; _msglabel. ZOrder=101; Self. userinteractionenabled=YES; Self. ZOrder=0; _balls = [NsmutablearrayArray]; _viewsize = [Ccdirector shareddirector]. Viewsize; }

The code does roughly the following:

    1. Creating a shared instance of itself
    2. Add current level scene, level scene we blog post in the back
    3. Initialize bounce sticks and physical worlds
    4. Set the z-order for each scene

(no.00004) iOS implementation play brick Game (v): Game Scene class

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.