We need to add monsters to view this part. First, let's look at the figure below: This is what we want to achieve, it is easy to see that the content displayed by each monster is similar to that in its similarity. Here we need to add two classes of MonsterInformation (view the monster Information Main Interface) and MonsterInformationCell (a single monster display information block). First let's take a look at MonsterInformation. h file code: # import <Foundation/Foundation. h> # import "cocos2d. h "@ class Enemy; @ class Hero; @ interface MonsterInformation: CCLayer {// mxtiledmap * mapBackground; Hero * hero;} // array of monsters in the current layer @ property (nonatomic, retain) NSMutableArray * mosterArray; // Number of monster lists @ property (nonatomic, assign) int mosterListCount; // whether to remove Interface @ property (nonatomic, assign) bool removeView; // loads the monster list-(void) ViewInit :( Enemy *) monster; // updates lost blood volume-(void) updateLossHP; the @ end class has three attributes: the first is the array storing the information of the current layer's monsters, the second is the reference count of the List of monsters, and the third is used to determine whether the interface can be removed. Then we start to add MonsterInformation. m file code: # import "MonsterInformation. h "# import" MonsterInformationCell. h "# import" Monster. h "# import" Hero. h "@ implementation MonsterInformation @ synthesize mosterArray; @ synthesize mosterListCount; @ synthesize removeView;-(id) init {if (self = [super init]) {// background mapBackground = [CCTMXTiledMap tiledMapWithTMXFile: @ "shopbg. tmx "]; mapBackground. position = ccp (10, 50); mapBackground. Scale = 2.2; [self addChild: mapBackground]; self. mosterArray = [[[NSMutableArray alloc] init] autorelease];} returnself;}-(void) ViewInit :( Enemy *) monster {// obtain the screen size CGSize size = [[ccdirectorshareddire] winSize]; // determine whether the current monster information array is empty if (self. mosterArray. count = 0) {// If yes, initialize the monster information tag and add it to the array. mosterListCount = 1; MonsterInformationCell * cell = [[[MonsterInformationCellalloc] init] autorelease]; [cell view Init: monster]; cell. position = ccp (30, size. height-80 * mosterListCount-14); [self. mosterArrayaddObject: cell]; [selfaddChild: cell];} else {// if not, first determine whether the current monster information tag already exists in the array bool sa = NO; for (MonsterInformationCell * cellinself. mosterArray) {if (cell. enemy. enemyID = monster. enemyID) {// If so, add 1 cell to the Monster tag count. count ++; sa = YES ;}} if (! Sa) {// if not, initialize the monster information tag and add it to the array mosterListCount + = 1; MonsterInformationCell * cell = [[[MonsterInformationCellalloc] init] autorelease]; [cell viewInit: monster]; cell. position = ccp (30, size. height-80 * mosterListCount-14); [self. mosterArrayaddObject: cell]; [selfaddChild: cell] ;}}- (void) updateLossHP {for (MonsterInformationCell * cellinself. mosterArray) {hero = [Hero getHero]; int enemyHp, _ heroHp; ene MyHp = cell. enemy. HP; _ heroHp = 0; if (hero. attack> cell. enemy. defense) {do {enemyHp-= (hero. attack-cell. enemy. defense); if (enemyHp> 0) {if (cell. enemy. attack-hero. defense)> 0) {_ heroHp + = (cell. enemy. attack-hero. defense) ;}}while (enemyHp> 0); [cell updateLossHP: _ heroHp] ;}}@ end our main page for viewing monster information is available, next, let's talk about the MonsterInformationCell class. Let's first look at the header file: # import <Foundation/Foundation. h> # import "cocos 2d. h "# import" Monster. h "@ interface MonsterInformationCell: CCLayer {// warrior blood loss CCLabelTTF * label61;} @ property (nonatomic, retain) Enemy * enemy; @ property (nonatomic, assign) int count; // initialize the monster information tag-(void) viewInit :( Enemy *) monster; // update the Lost Life-(void) updateLossHP :( int) lossHp; @ end there is only one tag for our class to be updated, that is, the warrior's loss of blood tag. There are two attributes: one is a monster and the other is the number of monsters. There are two other methods, one is the initialization tag, and the other is used to update the blood volume to be lost by the warriors. The code in the implementation file is as follows: # import "MonsterInformationCell. h "@ implementation MonsterInformationCell @ synthesize enemy; @ synthesize count;-(id) init {if (self = [superinit]) {self. count = 1;} returnself;}-(void) viewInit :( Enemy *) monster {self. enemy = monster; monster. scale = 2.0; monster. anchorPoint = ccp (0, 0); monster. position = ccp (0,-10); [selfaddChild: monster]; // CCLabelTTF * label1 = [[CCLabelTTFalloc] I NitWithString: @ "name" fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label2 = [[CCLabelTTFalloc] initWithString: @ "attack" fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label3 = [[CCLabelTTFalloc] initWithString: @ "Jin * Jing" fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label4 = [[CCLabelTTFalloc] initWithString: @ "life" fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label5 = [[CCLabelTTFalloc] success Ng: @ "defense" fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label6 = [[CCLabelTTFalloc] initWithString: @ "loss" fontName: @ "Verdana-Bold" fontSize: 20]; // CCLabelTTF * label11 = [[CCLabelTTF alloc] initWithString: [NSStringstringWithFormat: @ "% @", monster. name] fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label21 = [[CCLabelTTF alloc] initWithString: [NSStringstringWithFormat: @ "% d", monster. attack] fontName :@ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label31 = [[CCLabelTTF alloc] initWithString: [NSStringstringWithFormat: @ "% d * % d", monster. coin, monster. experience] fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label41 = [[CCLabelTTF alloc] initWithString: [NSStringstringWithFormat: @ "% d", monster. HP] fontName: @ "Verdana-Bold" fontSize: 20]; CCLabelTTF * label51 = [[CCLabelTTF alloc] initWithString: [NSStringstring WithFormat: @ "% d", monster. defense] fontName: @ "Verdana-Bold" fontSize: 20]; label61 = [[CCLabelTTFalloc] initWithString: [NSStringstringWithFormat :@"??? "] FontName: @" Verdana-Bold "fontSize: 20]; // label position label1.position = ccp (); label11.position = ccp (); label2.position = ccp ); label21.position = ccp (); label3.position = ccp (); label31.position = ccp (); label4.position = ccp (); label41.position = ccp ); label5.position = ccp (); label51.position = ccp (); label6.position = ccp (); label61.position = ccp (6 ); // Load the label [selfaddChild: label1]; [selfaddChild: label11]; [selfaddChild: label2]; [selfaddChild: label21]; [selfaddChild: label3]; [selfaddChild: label31]; [selfaddChild: label4]; [selfaddChild: label41]; [selfaddChild: label5]; [tags: label51]; [selfaddChild: label6]; [selfaddChild: label61];} // update loss of life-(void) updateLossHP :( int) lossHp {[label61setString: [NSStringstringWithFormat: @ "% d", lossHp];} @ End there are all labels. Let's take a look at the following MonsterInformation method to update the blood volume. We can retrieve the monster information by traversing the array to determine and update the lost blood volume. Well, these two classes have been created, and the following is the question of how to use them. There are two ways to initialize a map when you need to view it in the game; the other is to directly create a map when loading it as part of the map, then, call it directly. I will not discuss the advantages of the two methods. If you are interested, you can try either of them. Here I am using the second method, so we will add code in TitledMap below. First, we need to add an attribute: @ property (nonatomic, retain) MonsterInformation * monsterInfor; and instantiate monsterInfor: self in the initialization method. monsterInfor = [[[MonsterInformationalloc] init] autorelease]; then we add a method for creating the monster information interface:-(void) createMonsterInformation {for (int x = 0; x <= 10; x ++) {for (int y = 0; y <= 10; y ++) {CGPoint towerLoc = CGPointMake (x, y ); int enemy_tileGid = [self. enemytileGIDAt: towerLoc]; if (enemy_tileGid) {NSDi Ctionary * props = [self propertiesForGID: enemy_tileGid]; NSString * value = [props valueForKey: @ "enemy"]; int type = [value intValue]; enemy * enemy = [Monster initWith: type]; [self. monsterInforViewInit: enemy] ;}} return ;}here we traverse the monster layer to obtain the monster information and add it to the monster information interface. Then we call it in the initialization method. [SelfcreateMonsterInformation]; let's call it in Game01! Yesterday we have added the icon. Now we will add its response event: if (openpredict) {if (CGRectIntersectsRect (Rect, RectPredict) {if (! Self. curtitleMap. monsterInfor. removeView) {if (! FlyFloor. removeView) {[selfonPredict]; self. curtitleMap. monsterInfor. removeView = YES; _ hero. the isFighting = YES ;}}} code is added to the floor aircraft touch detection. The method for removing the floor aircraft is as follows, to control whether to enable the insight pin, we should have a prop in our game that can be used only when it is eaten. Therefore, we need to add it to the if (value4) of the item detection: openpredict = YES; in addition, a new method onPredict is also called: // update and load the interface for viewing monster information-(void) onPredict {if (self. curtitleMap. monsterInfor. mosterListCount> 0) {[self. curtitleMap. monsterInfo RupdateLossHP]; [selfaddChild: self. curtitleMap. monsterInfor]; self. curtitleMap. monsterInfor. position = ccp () ;}} so that we can use the insight pin, but to test, we can assign the openpredict toggle variable to YES in the initialization method. Run the command to see if it is the same as the first part. If the same, let's add the last part of the code! The function of this part of the code is to remove the information of the dead monsters from our monster information display interface. Obviously, this part of code should be added to the removeEnemy method. The Code is as follows: MonsterInformationCell * removecell = nil; for (MonsterInformationCell * cellinself. curtitleMap. monsterInfor. mosterArray) {if (cell. enemy. enemyID = self. selenemy. enemyID) {// if the corresponding monster information tag is found, the count is reduced by 1 cell. count-= 1; // when the monster information tag count is equal to zero, we remove it and the list count is reduced by 1 if (cell. count = 0) {removecell = cell; [cell. parentremoveChild: cellcleanup: YES]; self. curtitleMap. monsterInfor. moste RListCount-= 1 ;}}// if a monster information tag is removed, delete it from the array and relay the interface if (removecell) {[self. curtitleMap. monsterInfor. mosterArrayremoveObject: removecell]; int I = 1; for (MonsterInformationCell * cellinself. curtitleMap. monsterInfor. mosterArray) {cell. position = ccp (30, size. height-80 * I-14); I + = 1;} now, we have added this part. Run it!: Our game tutorial is coming to an end !!!