Next we start to add yesterday's content. First, our game interface is divided into two parts (game map layer and hero information layer). we add the file Game01 (game map layer ), herohp (Hero information layer), Hero (Hero) three files (here my naming is not very standard can be modified by myself) Hero. h file code # import <Foundation/Foundation. h> # import "cocos2d. h "// warrior @ interface Hero: CCSprite {}// blood volume @ property (nonatomic, assign) int HP; // Attack @ property (nonatomic, assign) int Attack; // Defense @ property (nonatomic, assign) int Defense; @ property (nonatomic, retain) CCAction * reply action; @ property (nonatomic, ret Ain) CCAction * moveAction; @ property (nonatomic, retain) CCAction * moveActions; // whether it is in combat status @ property (nonatomic, assign) bool isFighting; + (Hero *) getHero; @ endHero. m file code # import "Hero. h "@ implementation Hero @ synthesize HP; @ synthesize Attack; @ synthesize Defense; @ synthesize moveAction; @ synthesize limit action; @ synthesize moveActions; @ synthesize limit; Limit * _ hero = nil; -(id) initWith {CCTexture2D * heroTextu Re = [[resize] addImage: @ "hero.png"]; CCSpriteFrame * frame = [CCSpriteFrame frameWithTexture: heroTexture rect: CGRectMake (, 32)]; if (self = [superinitWithSpriteFrame: frame]) {self. HP = 1000; self. attack = 10; self. defense = 10;} returnself;} + (Hero *) getHero {if (! _ Hero) {_ hero = [[self alloc] initWith];} return _ hero;}-(void) dealloc {self. required action = nil; self. moveAction = nil; [superdealloc];} @ end here I will explain the Hero file code section. First, we only have one warrior in the game. So I wrote it as Singleton mode. Our warrior has three attributes: blood volume, attack, and defense. Game01.h File Code # import <Foundation/Foundation. h> # import "cocos2d. h "@ classHero; @ interface Game01: CCLayer {CGSize size; // map CCTMXTiledMap * curTiledMap; Hero * _ hero;} @ property (nonatomic, retain) Hero * hero; @ endGame01.m File Code # import "Game01.h" # import "Hero. h "int _ scale = 2; # define DOWNMIN50 # define LEFTMIN10 # define UPMAX750 # define RIGHTMAX690 @ implementation Game01 @ synthesize hero = _ hero;-(id) init {if (self = [Superinit]) {// obtain the screen size = [[ccdirectorsharedctor] winSize]; // load the game map curTiledMap = [CCTMXTiledMaptiledMapWithTMXFile: @ "1.tmx"]; curTiledMap. scale = _ scale; curTiledMap. position = ccp (LEFTMIN, DOWNMIN); [selfaddChild: curTiledMap]; // Add warrior _ hero = [Hero getHero]; [_ hero. parentremoveChild: _ herocleanup: YES]; _ hero. scale = _ scale; _ hero. anchorPoint = ccp (0, 0); // Add the protagonist _ hero. position = CGPointMake (LE FTMIN + (5*32 * _ scale), DOWNMIN + (32 * _ scale); [selfaddChild: _ hero];} returnself ;} @ endGame01 some code is used to add game maps and warriors. (the code is not much, but it is very important) Herohp. h file code # import <Foundation/Foundation. h> # import "cocos2d. h "@ classHero; @ interface Herohp: CCLayer {// set the map parameter CCTMXTiledMap * mapBackground; CCTMXTiledMap * background; // The hero level CCSprite * heroGrade; // The yellow key CCSprite * Key1; // The blue key CCSprite * Key2; // The red key CCSprite * Key3; // The ccl cclccl TTF * GradeLable; optional * maid; Carbon abelttf * AttLable; Carbon abelttf * DefLable; temperature * CoinLable; temperature * ExperienceLable; // key quantity tag Key1Lable; Carbon abelttf * Key2Lable; CCLabelTTF * Key3Lable; // floor label CCLabelTTF * floorValue; CCMenuItemFont * saveGame; Role * readGame; Role * exitGame; CCMenuItemFont * restartGame; // GameModel * model; // coin int _ coin; // experience int _ expe Rience; // blue key int _ yellowKey; // yellow key int _ blueKey; // red key int _ redKey; // level int _ grade;} @ property (nonatomic, retain) hero * hero; // gold Coin @ property (nonatomic, assign) int Coin; // Experience @ property (nonatomic, assign) int Experience; // yellow key @ property (nonatomic, assign) int YellowKey; // blue key @ property (nonatomic, assign) int BlueKey; // red key @ property (nonatomic, assign) int RedKey; // hero level @ property (nonatomic, assign) int Grade; + (Heroh P *) sharedHP; @ endHerohp. m file code # import "Herohp. h "# import" Hero. h "# define X750 # define Y150 @ implementation Herohp @ synthesize hero; @ synthesize Coin; @ synthesize Experience; @ synthesize YellowKey = _ YellowKey; @ synthesize BlueKey = _ BlueKey; @ synthesize RedKey = _ RedKey; @ synthesize Grade; staticHerohp * _ 1_hp = nil; + (Herohp *) sharedHP {@ synchronized ([Herohpclass]) {if (! _ Pipeline HP) {_ pipeline HP = [[self alloc] init];} return _ pipeline HP;} returnnil;}-(id) init {if (self = [superinit]) {self. hero = [HerogetHero]; CGSize size = [[CCDirector shareddire] winSize]; // background mapBackground = [CCTMXTiledMaptiledMapWithTMXFile: @ "background. tmx "]; mapBackground. position = ccp (0, 0); [selfaddChild: mapBackground]; background = [CCTMXTiledMaptiledMapWithTMXFile: @ "heroHp. tmx "]; ba Ckground. scale= 1.9; background. scalex= 2.5; background. position = ccp (X, Y); [selfaddChild: background]; CCTexture2D * heroTexture = [Blank] addImage: @ "hero.png"]; CCSpriteFrame * frame = [CCSpriteFrame frameWithTexture: heroTexture rect: CGRectMake (0, 0, 32, 32)]; heroGrade = [CCSprite spriteWithSpriteFrame: frame]; heroGrade. scale = 2.0; heroGrade. anchorPoint = ccp (0, 0); heroGrad E. position = ccp (X + 15, size. height-90); [selfaddChild: heroGrade]; // level label GradeLable = [CCLabelTTFlabelWithString: @ "Level 1" fontName: @ "Verdana-Bold" fontSize: 36]; gradeLable. anchorPoint = ccp (1, 0); GradeLable. position = ccp (X + 190, size. height-85); [selfaddChild: GradeLable]; maid = [CCLabelTTF labelWithString: [NSString stringWithFormat: @ "life % d", self. hero. HP] fontName: @ "Verdana-Bold" fontSize: 32]; Maid. anchorPoint = ccp (0, 0); maid. position = ccp (X + 20, size. height-130); [selfaddChild: Maid]; // [self schedule: @ selector (updateHeroHp :) interval: 1]; AttLable = [CCLabelTTF labelWithString: [NSString stringWithFormat: @ "attack % d", self. hero. attack] fontName: @ "Verdana-Bold" fontSize: 32]; AttLable. anchorPoint = ccp (0, 0); AttLable. position = ccp (X + 20, size. height-175); [selfaddChild: AttLable]; D EfLable = [CCLabelTTF labelWithString: [NSString stringWithFormat: @ "defense % d", self. hero. defense] fontName: @ "Verdana-Bold" fontSize: 32]; DefLable. anchorPoint = ccp (0, 0); DefLable. position = ccp (X + 20, size. height-220); [selfaddChild: DefLable]; CoinLable = [CCLabelTTFlabelWithString: @ "0" fontName: @ "Verdana-Bold" fontSize: 32]; CoinLable. anchorPoint = ccp (0, 0); CoinLable. position = ccp (X + 20, size. height -265); [selfaddChild: CoinLable]; ExperienceLable = [CCLabelTTFlabelWithString: @ "experience 0" fontName: @ "Verdana-Bold" fontSize: 32]; ExperienceLable. anchorPoint = ccp (0, 0); ExperienceLable. position = ccp (X + 20, size. height-310); [selfaddChild: ExperienceLable]; self. coin = 0; self. experience = 0; self. grade = 1; // key icon and quantity label self. yellowKey = 0; self. blueKey = 0; self. redKey = 0; CCTexture2D * KeyTexture = [C Optional] addImage: @ "item.png"]; optional * key1 = [CCSpriteFrame frameWithTexture: KeyTexture rect: CGRectMake (* 32, 32)]; optional * key2 = [invalid frameWithTexture: keyTexture rect: CGRectMake (1*32, 4*32, 32)]; CCSpriteFrame * key3 = [invalid frameWithTexture: KeyTexture rect: CGRectMake (2*32, 4*32, 32)]; key1 = [CCSpritespriteWithSpriteFrame: key1]; Key 1. scale = 1.6; Key1.anchorPoint = ccp (0, 0); Key1.position = ccp (X + 15, size. height-360); [selfaddChild: Key1]; Key1Lable = [CCLabelTTFlabelWithString: @ "0" fontName: @ "Verdana-Bold" fontSize: 35]; Key1Lable. anchorPoint = ccp (1, 0); Key1Lable. position = ccp (X + 170, size. height-360); [selfaddChild: Key1Lable]; Key2 = [CCSpritespriteWithSpriteFrame: key2]; Key2.scale = 1.6; Key2.anchorPoint = ccp (0, 0); K Ey2.position = ccp (X + 15, size. height-410); [selfaddChild: Key2]; Key2Lable = [CCLabelTTFlabelWithString: @ "0" fontName: @ "Verdana-Bold" fontSize: 35]; Key2Lable. anchorPoint = ccp (1, 0); Key2Lable. position = ccp (X + 170, size. height-410); [selfaddChild: Key2Lable]; Key3 = [CCSpritespriteWithSpriteFrame: key3]; Key3.scale = 1.6; Key3.anchorPoint = ccp (0, 0); Key3.position = ccp (X + 15, size. height-460 ); [SelfaddChild: Key3]; Key3Lable = [CCLabelTTFlabelWithString: @ "0" fontName: @ "Verdana-Bold" fontSize: 35]; Key3Lable. anchorPoint = ccp (1, 0); Key3Lable. position = ccp (X + 170, size. height-460); [selfaddChild: Key3Lable]; floorValue = [CCLabelTTFlabelWithString: @ "" fontName: @ "Verdana-Bold" fontSize: 35]; floorValue. position = ccp (X + 110, size. height-490); [selfaddChild: floorValue]; // click "saveGame" = [CCM EnuItemFont itemFromString: @ "save" target: selfselector: @ selector (onsaveGame)]; saveGame. fontSize = 28; saveGame. fontName = @ "Verdana-Bold"; CCMenu * menu1 = [CCMenu menuWithItems: saveGame, nil]; menu1.position = ccp (X + 40, size. height-535); [selfaddChild: menu1]; readGame = [CCMenuItemFont itemFromString: @ "read" target: selfselector: @ selector (onreadGame)]; readGame. fontSize = 28; readGame. fontName = @ "Verdan A-Bold "; CCMenu * menu2 = [CCMenu menuWithItems: readGame, nil]; menu2.position = ccp (X + 40, size. height-580); [selfaddChild: menu2]; restartGame = [CCMenuItemFont itemFromString: @ "restart" target: self selector: @ selector (onrestartGame)]; restartGame. fontSize = 28; restartGame. fontName = @ "Verdana-Bold"; CCMenu * menu3 = [CCMenu menuWithItems: restartGame, nil]; menu3.position = ccp (X + 160, size. height-535); [SelfaddChild: menu3]; exitGame = [CCMenuItemFont itemFromString: @ "exit game" target: self selector: @ selector (onexitGame)]; exitGame. fontSize = 28; exitGame. fontName = @ "Verdana-Bold"; CCMenu * menu4 = [CCMenu menuWithItems: exitGame, nil]; menu4.position = ccp (X + 160, size. height-580); [selfaddChild: menu4];} returnself;}-(void) onsaveGame {}-(void) onreadGame {}-(void) onrestartGame {}-(void) onexitGame {[[CCD IrectorsharedDirector] end]; # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) exit (0); # endif} @ end next Let's explain Herohp's code, which is a bit more code, however, many of them are repeated and difficult. This part mainly includes the basic information of the Warrior: Warrior level, three attributes of the warrior, number of keys, floor labels, and menu items. Here, only menu items are implemented by CCMenu, and other items are implemented by CCLable. The warrior information class also uses the singleton mode !!! Then in Scenemanager. add CCDirector * director = [ccdirectorshareddire]; CCScene * scene = [CCScene node]; if ([director runningScene]) {[director replaceScene: scene];} else {[director runWithScene: scene];} Herohp * layer2 = [Herohp sharedHP]; [scene addChild: layer2 z: 0]; game01 * layer = [Game01 node]; [scene addChild: layer z: 1]; then, run the following command to get a static interface, everything on the interface is static,