cocos2d-iphone之魔塔20層第八部分

原文連接http://blog.csdn.net/fire_work/article/details/8608551 html

  爲了感謝你們對個人支持這裏給你們提供一下這八部分的代碼下載

    昨天咱們的勇士能夠穿越樓層了,可是咱們的遊戲界面還不夠「生動」,接下來咱們就要 測試

添加一些代碼使其「生動」起來。 動畫

    這部分代碼很少可是卻能讓地圖上的怪物都動來,那麼就讓咱們來添加一下這部分代 atom

碼吧,這部分代碼須要添加到TitledMap.m中titledMapAnalytic方法中if(heroPoint_tileGid) spa

循環的下面如圖: .net


  1. if (enemy_tileGid)  
  2.             { 
  3.                 NSDictionary *props = [self propertiesForGID:enemy_tileGid]; 
  4.                 NSString *value = [props valueForKey:@"enemy"]; 
  5.                 int type = [value intValue]; 
  6.                 CCTexture2D *Texture = [[CCTextureCache sharedTextureCache] addImage:@"enemy.png"]; 
  7.                 CCSpriteFrame *frame0 ,*frame1,*frame2,*frame3; 
  8. //第二個參數表示顯示區域的x, y, width, height,根據type來肯定顯示的y座標
  9.                 frame0 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*0, type*32, 32, 32)]; 
  10.                 frame1 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*1, type*32, 32, 32)]; 
  11.                 frame2 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*2, type*32, 32, 32)]; 
  12.                 frame3 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*3, type*32, 32, 32)]; 
  13.                 NSMutableArray *animFrames = [NSMutableArray array]; 
  14.                 [animFrames addObject:frame0]; 
  15.                 [animFrames addObject:frame1]; 
  16.                 [animFrames addObject:frame2]; 
  17.                 [animFrames addObject:frame3]; 
  18.                 //循環動畫序列 
  19.                 CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.2f]; 
  20.                 CCAnimate *animate = [CCAnimate actionWithAnimation:animation]; 
  21.                 CCSequence *seq = [CCSequence actions: animate,nil]; 
  22.                 [[self.enemy tileAt:towerLoc]runAction:[CCRepeatForever actionWithAction: seq]]; 
  23.             } 

if (enemy_tileGid) 
            {
                NSDictionary *props = [self propertiesForGID:enemy_tileGid];
                NSString *value = [props valueForKey:@"enemy"];
                int type = [value intValue];
                CCTexture2D *Texture = [[CCTextureCache sharedTextureCache] addImage:@"enemy.png"];
                CCSpriteFrame *frame0 ,*frame1,*frame2,*frame3;
                //第二個參數表示顯示區域的x, y, width, height,根據type來肯定顯示的y座標
                frame0 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*0, type*32, 32, 32)];
                frame1 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*1, type*32, 32, 32)];
                frame2 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*2, type*32, 32, 32)];
                frame3 = [CCSpriteFrame frameWithTexture:Texture rect:CGRectMake(32*3, type*32, 32, 32)];
                NSMutableArray *animFrames = [NSMutableArray array];
                [animFrames addObject:frame0];
                [animFrames addObject:frame1];
                [animFrames addObject:frame2];
                [animFrames addObject:frame3];
                //循環動畫序列
                CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.2f];
                CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
                CCSequence *seq = [CCSequence actions: animate,nil];
                [[self.enemy tileAt:towerLoc]runAction:[CCRepeatForever actionWithAction: seq]];
            }


這個跟以前的開門動畫加載方式差很少我就很少講了。運行一下游戲,你就會發現咱們的怪物 設計

動起來了,這樣看着是否是更有感受了! code

下面讓咱們隨着遊戲一直來到三樓,直接到商店你會發現商店沒有任何響應,接下來咱們就要 orm

開始添加商店的響應事件了,不過在這以前咱們要先把咱們的商店界面設計好。代碼: htm

ShopLayer.h文件內容

  1. #import <Foundation/Foundation.h> 
  2. #import "cocos2d.h" 
  3.  
  4. @interface ShopLayer : CCLayer 
  5.     CCLabelTTF *introduction; 
  6.     CCLabelTTF *addHP; 
  7.     CCLabelTTF *addAttack; 
  8.     CCLabelTTF *addDefense; 
  9.     CCLabelTTF *exitShop; 
  10.     CCLabelTTF *enter; 
  11. @property (nonatomic,assign)int curHP; 
  12. @property (nonatomic,assign)int curAttack; 
  13. @property (nonatomic,assign)int curDefense; 
  14. @property (nonatomic,assign)int curCoin; 
  15. //當前選中商店編號 
  16. @property (nonatomic,assign) int selID; 
  17. //是否在購買狀態 
  18. @property (nonatomic,assign) int isOnShop; 
  19. @property (nonatomic,retain) CCSprite *selSprite;  
  20.  
  21. -(id)initWithID:(int) shopID; 
  22. @end 

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface ShopLayer : CCLayer
{
    CCLabelTTF *introduction;
    CCLabelTTF *addHP;
    CCLabelTTF *addAttack;
    CCLabelTTF *addDefense;
    CCLabelTTF *exitShop;
    CCLabelTTF *enter;
}
@property (nonatomic,assign)int curHP;
@property (nonatomic,assign)int curAttack;
@property (nonatomic,assign)int curDefense;
@property (nonatomic,assign)int curCoin;
//當前選中商店編號
@property (nonatomic,assign) int selID;
//是否在購買狀態
@property (nonatomic,assign) int isOnShop;
@property (nonatomic,retain) CCSprite *selSprite; 

-(id)initWithID:(int) shopID;
@end


ShopLayer.m文件內容

  1. #import "ShopLayer.h" 
  2. #import "Hero.h" 
  3. #import "Herohp.h" 
  4.  
  5. @implementation ShopLayer 
  6. @synthesize curHP; 
  7. @synthesize curCoin; 
  8. @synthesize curAttack; 
  9. @synthesize curDefense; 
  10. @synthesize selSprite; 
  11. @synthesize isOnShop; 
  12. @synthesize selID; 
  13.  
  14. -(void)viewInit 
  15.     //獲取屏幕大小 
  16.     CGSize size = [[CCDirector sharedDirector] winSize]; 
  17.     self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"]; 
  18.     self.selSprite.scaleX = 2.0; 
  19.     id blink = [CCBlink actionWithDuration:2 blinks:2]; 
  20.     [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]]; 
  21.     self.selID = 0
  22.     //背景 
  23.     CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"]; 
  24.     background.scale = 2.0; 
  25.     background.position = ccp(40, size.height / 2 - 200); 
  26.     [self addChild:background]; 
  27.     //介紹標籤 
  28.     introduction = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"勇士你好,這裏是商店你花%d金幣便可選擇一下任意一項",self.curCoin] dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32]; 
  29.     introduction.position = ccp(350, size.height - 165); 
  30.     [self addChild:introduction]; 
  31.     //加血標籤 
  32.     addHP = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d血量",self.curHP] fontName:@"Verdana-Bold" fontSize:30]; 
  33.     addHP.position = ccp(350, size.height - 260); 
  34.     [self addChild:addHP]; 
  35.     //加攻標籤 
  36.     addAttack = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d攻擊",self.curAttack] fontName:@"Verdana-Bold" fontSize:30]; 
  37.     addAttack.position = ccp(350, size.height - 320); 
  38.     [self addChild:addAttack]; 
  39.     //加防標籤 
  40.     addDefense = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d防護",self.curDefense] fontName:@"Verdana-Bold" fontSize:30]; 
  41.     addDefense.position = ccp(350, size.height - 380); 
  42.     [self addChild:addDefense]; 
  43.     //離開商店 
  44.     exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30]; 
  45.     exitShop.position = ccp(350, size.height - 440); 
  46.     [self addChild:exitShop]; 
  47.     //肯定 
  48.     enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30]; 
  49.     enter.position = ccp(350,size.height - 500); 
  50.     [self addChild:enter]; 
  51.     [self addChild:self.selSprite]; 
  52.     self.selSprite.position = addHP.position; 
  53. -(id)initWithID:(int) shopID 
  54.     if ((self = [super init]))  
  55.     { 
  56.         if (shopID == 1)  
  57.         { 
  58.             self.curCoin = 25
  59.             self.curAttack = 4
  60.             self.curDefense = 4
  61.             self.curHP = 800
  62.         } 
  63.         else 
  64.         { 
  65.             self.curCoin = 100
  66.             self.curAttack = 20
  67.             self.curDefense = 20
  68.             self.curHP = 4000
  69.         } 
  70.         [self viewInit]; 
  71.     } 
  72.     return self; 
  73. @end 

#import "ShopLayer.h"
#import "Hero.h"
#import "Herohp.h"

@implementation ShopLayer
@synthesize curHP;
@synthesize curCoin;
@synthesize curAttack;
@synthesize curDefense;
@synthesize selSprite;
@synthesize isOnShop;
@synthesize selID;

-(void)viewInit
{
    //獲取屏幕大小
    CGSize size = [[CCDirector sharedDirector] winSize];
    self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"];
    self.selSprite.scaleX = 2.0;
    id blink = [CCBlink actionWithDuration:2 blinks:2];
    [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]];
    self.selID = 0;
    //背景
    CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"];
    background.scale = 2.0;
    background.position = ccp(40, size.height / 2 - 200);
    [self addChild:background];
    //介紹標籤
    introduction = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"勇士你好,這裏是商店你花%d金幣便可選擇一下任意一項",self.curCoin] dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32];
    introduction.position = ccp(350, size.height - 165);
    [self addChild:introduction];
    //加血標籤
    addHP = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d血量",self.curHP] fontName:@"Verdana-Bold" fontSize:30];
    addHP.position = ccp(350, size.height - 260);
    [self addChild:addHP];
    //加攻標籤
    addAttack = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d攻擊",self.curAttack] fontName:@"Verdana-Bold" fontSize:30];
    addAttack.position = ccp(350, size.height - 320);
    [self addChild:addAttack];
    //加防標籤
    addDefense = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"增長%d防護",self.curDefense] fontName:@"Verdana-Bold" fontSize:30];
    addDefense.position = ccp(350, size.height - 380);
    [self addChild:addDefense];
    //離開商店
    exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30];
    exitShop.position = ccp(350, size.height - 440);
    [self addChild:exitShop];
    //肯定
    enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30];
    enter.position = ccp(350,size.height - 500);
    [self addChild:enter];
    [self addChild:self.selSprite];
    self.selSprite.position = addHP.position;
}
-(id)initWithID:(int) shopID
{
    if ((self = [super init])) 
    {
        if (shopID == 1) 
        {
            self.curCoin = 25;
            self.curAttack = 4;
            self.curDefense = 4;
            self.curHP = 800;
        }
        else
        {
            self.curCoin = 100;
            self.curAttack = 20;
            self.curDefense = 20;
            self.curHP = 4000;
        }
        [self viewInit];
    }
    return self;
}
@end


這部分代碼我就很少講了,下面咱們就開始添加Game01.m中調用部分和操做控制

首先咱們要在if(other_tileGid)方法中添加如下代碼:

  1. NSDictionary *props = [self.curtitleMap propertiesForGID:other_tileGid]; 
  2. NSString *value = [props valueForKey:@"shop"]; 
  3. int type = [value intValue]; 
  4. if (type)  
  5.    _hero.isFighting = YES
  6.    shop = [[ShopLayer alloc] initWithID:type]; 
  7.    shop.isOnShop = YES
  8.    [self addChild:shop]; 

NSDictionary *props = [self.curtitleMap propertiesForGID:other_tileGid];
NSString *value = [props valueForKey:@"shop"];
int type = [value intValue];
if (type) 
{
   _hero.isFighting = YES;
   shop = [[ShopLayer alloc] initWithID:type];
   shop.isOnShop = YES;
   [self addChild:shop];
}


當咱們在購買狀態時是不能進行除了商店之外的操做的,因此我把勇士的戰鬥狀態賦值爲YES

在咱們這個遊戲中是有兩個商店的,因此咱們在初始化商店的時候經過商店編號來識別。

到這裏咱們的商店界面出現了,下面就要開始添加商店操做了,這部分代碼須要添加到

Game01.m文件的觸摸響應事件中去

  1. if (shop.isOnShop)  
  2.     { 
  3.         for (int i = 0; i <= 4; i++)  
  4.         { 
  5.             CGRect Rect1 = CGRectMake(200, 
  6.                                       size.height - 290 - i*60, 
  7.                                       400, 
  8.                                       60); 
  9.             //檢測觸點是否在控件區 
  10.             if (CGRectIntersectsRect(Rect, Rect1)) 
  11.             { 
  12.                 if (i == 4)  
  13.                 { 
  14.                     if (herohp.Coin >= shop.curCoin)  
  15.                     { 
  16.                         switch (shop.selID) 
  17.                         { 
  18.                             case 0: 
  19.                                 _hero.HP += shop.curHP; 
  20.                                 [herohp updateHeroHp]; 
  21.                                 break; 
  22.                             case 1: 
  23.                                 _hero.Attack += shop.curAttack; 
  24.                                 [herohp updateHeroAttack]; 
  25.                                 break; 
  26.                             case 2: 
  27.                                 _hero.Defense += shop.curDefense; 
  28.                                 [herohp updateHeroDefense]; 
  29.                                 break; 
  30.                             default: 
  31.                                 break; 
  32.                         } 
  33.                         herohp.Coin -= shop.curCoin; 
  34.                         [herohp updateCoin]; 
  35.                     } 
  36.                 } 
  37.                 else if (i == 3)  
  38.                 { 
  39.                     _hero.isFighting = NO
  40.                     shop.isOnShop = NO
  41.                     [self removeChild:shop cleanup:YES]; 
  42.                 } 
  43.                 else 
  44.                     shop.selID = i
  45.                 if (i<3)  
  46.                 { 
  47.                     shop.selSprite.position = ccp(350, size.height - 260 - i*60); 
  48.                 } 
  49.             } 
  50.         } 
  51.     } 

if (shop.isOnShop) 
    {
        for (int i = 0; i <= 4; i++) 
        {
            CGRect Rect1 = CGRectMake(200,
                                      size.height - 290 - i*60,
                                      400,
                                      60);
            //檢測觸點是否在控件區
            if (CGRectIntersectsRect(Rect, Rect1))
            {
                if (i == 4) 
                {
                    if (herohp.Coin >= shop.curCoin) 
                    {
                        switch (shop.selID)
                        {
                            case 0:
                                _hero.HP += shop.curHP;
                                [herohp updateHeroHp];
                                break;
                            case 1:
                                _hero.Attack += shop.curAttack;
                                [herohp updateHeroAttack];
                                break;
                            case 2:
                                _hero.Defense += shop.curDefense;
                                [herohp updateHeroDefense];
                                break;
                            default:
                                break;
                        }
                        herohp.Coin -= shop.curCoin;
                        [herohp updateCoin];
                    }
                }
                else if (i == 3) 
                {
                    _hero.isFighting = NO;
                    shop.isOnShop = NO;
                    [self removeChild:shop cleanup:YES];
                }
                else
                    shop.selID = i;
                if (i<3) 
                {
                    shop.selSprite.position = ccp(350, size.height - 260 - i*60);
                }
            }
        }
    }


終於咱們的商店能夠使用了,可是一個問題來了咱們沒有金幣啊,金幣是打怪的時候獲得的

那麼咱們就要在消除怪物的時候更新一下金幣和經驗了代碼以下:

  1. canmove = YES
  2.     herohp.Coin += self.selenemy.Coin; 
  3.     herohp.Experience += self.selenemy.Experience; 
  4.     [herohp updateCoin]; 
  5.     [herohp updateExperience]; 

canmove = YES;
    herohp.Coin += self.selenemy.Coin;
    herohp.Experience += self.selenemy.Experience;
    [herohp updateCoin];
    [herohp updateExperience];


這樣咱們就可以得到金幣和經驗了,不過爲了測試方便,這裏咱們能夠修改一些參數,

  1. self.HP = 10000
  2.         self.Attack = 1000
  3.         self.Defense = 1000

self.HP = 10000;
        self.Attack = 1000;
        self.Defense = 1000;


金幣和經驗也能夠適當修改,修改過以後,讓咱們再次隨着勇士的腳步來到5樓吧,這裏

你會看到兩個npc,地圖左邊的是神祕老人,右邊的是商人,神祕老人是能夠說是經驗商店

在這裏你能夠用經驗提高勇士的能力;商人是賣鑰匙的,在這裏你能夠買到各類鑰匙。

講到這裏咱們又須要添加兩個類Business和Buykey跟商店差很少這裏我就很少講了,直接

上代碼:

Business.h代碼:

  1. #import <Foundation/Foundation.h> 
  2. #import "cocos2d.h" 
  3.  
  4. @interface Business : CCLayer  
  5.     CCLabelTTF *introduction; 
  6.     CCLabelTTF *addGrade; 
  7.     CCLabelTTF *addAttack; 
  8.     CCLabelTTF *addDefense; 
  9.     CCLabelTTF *exitShop; 
  10.     CCLabelTTF *enter; 
  11.  
  12. @property (nonatomic,assign)int curUpgrade; 
  13. @property (nonatomic,assign)int curAttack; 
  14. @property (nonatomic,assign)int curDefense; 
  15. @property (nonatomic,assign)int curExperience; 
  16. @property (nonatomic,assign)int curExperience2; 
  17. //當前選中商店編號 
  18. @property (nonatomic,assign) int selID; 
  19. //是否在購買狀態 
  20. @property (nonatomic,assign) int isOnShop; 
  21. @property (nonatomic,retain) CCSprite *selSprite;  
  22.  
  23. -(id)initWithID:(int) shopID; 
  24. @end 

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface Business : CCLayer 
{
    CCLabelTTF *introduction;
    CCLabelTTF *addGrade;
    CCLabelTTF *addAttack;
    CCLabelTTF *addDefense;
    CCLabelTTF *exitShop;
    CCLabelTTF *enter;
}

@property (nonatomic,assign)int curUpgrade;
@property (nonatomic,assign)int curAttack;
@property (nonatomic,assign)int curDefense;
@property (nonatomic,assign)int curExperience;
@property (nonatomic,assign)int curExperience2;
//當前選中商店編號
@property (nonatomic,assign) int selID;
//是否在購買狀態
@property (nonatomic,assign) int isOnShop;
@property (nonatomic,retain) CCSprite *selSprite; 

-(id)initWithID:(int) shopID;
@end


Business.m代碼:

  1. #import "Business.h" 
  2.  
  3. @implementation Business 
  4. @synthesize curUpgrade; 
  5. @synthesize curExperience; 
  6. @synthesize curExperience2; 
  7. @synthesize curAttack; 
  8. @synthesize curDefense; 
  9. @synthesize selSprite; 
  10. @synthesize isOnShop; 
  11. @synthesize selID; 
  12.  
  13. -(void)viewInit 
  14.     //獲取屏幕大小 
  15.     CGSize size = [[CCDirector sharedDirector] winSize]; 
  16.     self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"]; 
  17.     self.selSprite.scaleX = 2.0; 
  18.     id blink = [CCBlink actionWithDuration:2 blinks:2]; 
  19.     [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]]; 
  20.     self.selID = 0
  21.     //背景 
  22.     CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"]; 
  23.     background.scale = 2.0; 
  24.     background.position = ccp(35, size.height / 2 - 200); 
  25.     [self addChild:background]; 
  26.     //介紹標籤 
  27.     introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,你能夠用經驗值提高本身的能力" fontName:@"Verdana-Bold" fontSize:30]; 
  28.     introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,你能夠用經驗值提高本身的能力" dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32]; 
  29.     introduction.position = ccp(350, size.height - 200); 
  30.     [self addChild:introduction]; 
  31.     //加血標籤 
  32.     addGrade = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗提高%d級",self.curExperience,self.curUpgrade] fontName:@"Verdana-Bold" fontSize:30]; 
  33.     addGrade.position = ccp(350, size.height - 260); 
  34.     [self addChild:addGrade]; 
  35.     //加攻標籤 
  36.     addAttack = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗增長%d攻擊",self.curExperience2,self.curAttack] fontName:@"Verdana-Bold" fontSize:30]; 
  37.     addAttack.position = ccp(350, size.height - 320); 
  38.     [self addChild:addAttack]; 
  39.     //加防標籤 
  40.     addDefense = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗增長%d防護",self.curExperience2,self.curDefense] fontName:@"Verdana-Bold" fontSize:30]; 
  41.     addDefense.position = ccp(350, size.height - 380); 
  42.     [self addChild:addDefense]; 
  43.     //離開商店 
  44.     exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30]; 
  45.     exitShop.position = ccp(350, size.height - 440); 
  46.     [self addChild:exitShop]; 
  47.     //肯定 
  48.     enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30]; 
  49.     enter.position = ccp(350,size.height - 500); 
  50.     [self addChild:enter]; 
  51.     [self addChild:self.selSprite]; 
  52.     self.selSprite.position = addGrade.position; 
  53. -(id)initWithID:(int) shopID 
  54.     if ((self = [super init]))  
  55.     { 
  56.         if (shopID == 4)  
  57.         { 
  58.             self.curUpgrade = 1
  59.             self.curAttack = 5
  60.             self.curDefense = 5
  61.             self.curExperience = 100
  62.             self.curExperience2 = 30
  63.         } 
  64.         else 
  65.         { 
  66.             self.curUpgrade = 3
  67.             self.curAttack = 17
  68.             self.curDefense = 17
  69.             self.curExperience = 270
  70.             self.curExperience2 = 90
  71.         } 
  72.         [self viewInit]; 
  73.     } 
  74.     return self; 
  75.  
  76. @end 

#import "Business.h"

@implementation Business
@synthesize curUpgrade;
@synthesize curExperience;
@synthesize curExperience2;
@synthesize curAttack;
@synthesize curDefense;
@synthesize selSprite;
@synthesize isOnShop;
@synthesize selID;

-(void)viewInit
{
    //獲取屏幕大小
    CGSize size = [[CCDirector sharedDirector] winSize];
    self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"];
    self.selSprite.scaleX = 2.0;
    id blink = [CCBlink actionWithDuration:2 blinks:2];
    [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]];
    self.selID = 0;
    //背景
    CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"];
    background.scale = 2.0;
    background.position = ccp(35, size.height / 2 - 200);
    [self addChild:background];
    //介紹標籤
    introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,你能夠用經驗值提高本身的能力" fontName:@"Verdana-Bold" fontSize:30];
    introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,你能夠用經驗值提高本身的能力" dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32];
    introduction.position = ccp(350, size.height - 200);
    [self addChild:introduction];
    //加血標籤
    addGrade = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗提高%d級",self.curExperience,self.curUpgrade] fontName:@"Verdana-Bold" fontSize:30];
    addGrade.position = ccp(350, size.height - 260);
    [self addChild:addGrade];
    //加攻標籤
    addAttack = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗增長%d攻擊",self.curExperience2,self.curAttack] fontName:@"Verdana-Bold" fontSize:30];
    addAttack.position = ccp(350, size.height - 320);
    [self addChild:addAttack];
    //加防標籤
    addDefense = [[CCLabelTTF alloc] initWithString:[NSString stringWithFormat:@"%d經驗增長%d防護",self.curExperience2,self.curDefense] fontName:@"Verdana-Bold" fontSize:30];
    addDefense.position = ccp(350, size.height - 380);
    [self addChild:addDefense];
    //離開商店
    exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30];
    exitShop.position = ccp(350, size.height - 440);
    [self addChild:exitShop];
    //肯定
    enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30];
    enter.position = ccp(350,size.height - 500);
    [self addChild:enter];
    [self addChild:self.selSprite];
    self.selSprite.position = addGrade.position;
}
-(id)initWithID:(int) shopID
{
    if ((self = [super init])) 
    {
        if (shopID == 4) 
        {
            self.curUpgrade = 1;
            self.curAttack = 5;
            self.curDefense = 5;
            self.curExperience = 100;
            self.curExperience2 = 30;
        }
        else
        {
            self.curUpgrade = 3;
            self.curAttack = 17;
            self.curDefense = 17;
            self.curExperience = 270;
            self.curExperience2 = 90;
        }
        [self viewInit];
    }
    return self;
}

@end


Buykey.h代碼:

  1. #import <Foundation/Foundation.h> 
  2. #import "cocos2d.h" 
  3.  
  4. @interface Buykey : CCLayer  
  5.     CCLabelTTF *introduction; 
  6.     CCLabelTTF *Key1Lable; 
  7.     CCLabelTTF *Key2Lable; 
  8.     CCLabelTTF *Key3Lable; 
  9.     CCLabelTTF *exitShop; 
  10.     CCLabelTTF *enter; 
  11.  
  12. @property (nonatomic,assign)int yellowKeyPrice; 
  13. @property (nonatomic,assign)int blueKeyPrice; 
  14. @property (nonatomic,assign)int redKeyPrice; 
  15. //當前選中商店編號 
  16. @property (nonatomic,assign) int selID; 
  17. //是否在購買狀態 
  18. @property (nonatomic,assign) int isOnShop; 
  19. @property (nonatomic,retain) CCSprite *selSprite;  
  20.  
  21. -(void)viewInit:(int) shopID; 
  22. @end 

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface Buykey : CCLayer 
{
    CCLabelTTF *introduction;
    CCLabelTTF *Key1Lable;
    CCLabelTTF *Key2Lable;
    CCLabelTTF *Key3Lable;
    CCLabelTTF *exitShop;
    CCLabelTTF *enter;
}

@property (nonatomic,assign)int yellowKeyPrice;
@property (nonatomic,assign)int blueKeyPrice;
@property (nonatomic,assign)int redKeyPrice;
//當前選中商店編號
@property (nonatomic,assign) int selID;
//是否在購買狀態
@property (nonatomic,assign) int isOnShop;
@property (nonatomic,retain) CCSprite *selSprite; 

-(void)viewInit:(int) shopID;
@end


Buykey.m代碼:

  1. #import "Buykey.h" 
  2.  
  3.  
  4. @implementation Buykey 
  5. @synthesize yellowKeyPrice; 
  6. @synthesize blueKeyPrice; 
  7. @synthesize redKeyPrice; 
  8. @synthesize selSprite; 
  9. @synthesize isOnShop; 
  10. @synthesize selID; 
  11.  
  12. -(void)viewInit:(int) shopID 
  13.     if (shopID == 5)  
  14.     { 
  15.         self.yellowKeyPrice = 10
  16.         self.blueKeyPrice = 50
  17.         self.redKeyPrice = 100
  18.         [introduction setString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你"]; 
  19.     } 
  20.     else 
  21.     { 
  22.         self.yellowKeyPrice = 5
  23.         self.blueKeyPrice = 25
  24.         self.redKeyPrice = 50
  25.         [introduction setString:@"勇士你好,若是你有多餘的鑰你能夠賣給我"]; 
  26.     } 
  27.     [Key1Lable setString:[NSString stringWithFormat:@"黃鑰匙(%d)",self.yellowKeyPrice]]; 
  28.     [Key2Lable setString:[NSString stringWithFormat:@"藍鑰匙(%d)",self.blueKeyPrice]]; 
  29.     [Key3Lable setString:[NSString stringWithFormat:@"紅鑰匙(%d)",self.redKeyPrice]]; 
  30.     [self removeChild:self.selSprite cleanup:YES]; 
  31.     id blink = [CCBlink actionWithDuration:2 blinks:2]; 
  32.     [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]]; 
  33.     [self addChild:self.selSprite]; 
  34.     self.selSprite.position = Key1Lable.position; 
  35. -(id)init 
  36.     if ((self = [super init]))  
  37.     { 
  38.         //獲取屏幕大小 
  39.         CGSize size = [[CCDirector sharedDirector] winSize]; 
  40.         self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"]; 
  41.         self.selSprite.scaleX = 2.0; 
  42.         id blink = [CCBlink actionWithDuration:2 blinks:2]; 
  43.         [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]]; 
  44.         self.selID = 0
  45.         //背景 
  46.         CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"]; 
  47.         background.scale = 2.0; 
  48.         background.position = ccp(35, size.height / 2 - 200); 
  49.         [self addChild:background]; 
  50.         //介紹標籤 
  51.         //introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你" fontName:@"Verdana-Bold" fontSize:30]; 
  52.         introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你" dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32]; 
  53.         introduction.position = ccp(350, size.height - 200); 
  54.         [self addChild:introduction]; 
  55.         //黃鑰匙標籤 
  56.         Key1Lable = [[CCLabelTTF alloc] initWithString:@"黃鑰匙(10)" fontName:@"Verdana-Bold" fontSize:30]; 
  57.         Key1Lable.position = ccp(350, size.height - 260); 
  58.         [self addChild:Key1Lable]; 
  59.         //藍鑰匙標籤 
  60.         Key2Lable = [[CCLabelTTF alloc] initWithString:@"藍鑰匙(50)" fontName:@"Verdana-Bold" fontSize:30]; 
  61.         Key2Lable.position = ccp(350, size.height - 320); 
  62.         [self addChild:Key2Lable]; 
  63.         //紅鑰匙標籤 
  64.         Key3Lable = [[CCLabelTTF alloc] initWithString:@"紅鑰匙(100)" fontName:@"Verdana-Bold" fontSize:30]; 
  65.         Key3Lable.position = ccp(350, size.height - 380); 
  66.         [self addChild:Key3Lable]; 
  67.         //離開商店 
  68.         exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30]; 
  69.         exitShop.position = ccp(350, size.height - 440); 
  70.         [self addChild:exitShop]; 
  71.         //肯定 
  72.         enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30]; 
  73.         enter.position = ccp(350,size.height - 500); 
  74.         [self addChild:enter]; 
  75.         [self addChild:self.selSprite]; 
  76.         self.selSprite.position = Key1Lable.position; 
  77.     } 
  78.     return self; 
  79. @end 

#import "Buykey.h"


@implementation Buykey
@synthesize yellowKeyPrice;
@synthesize blueKeyPrice;
@synthesize redKeyPrice;
@synthesize selSprite;
@synthesize isOnShop;
@synthesize selID;

-(void)viewInit:(int) shopID
{
    if (shopID == 5) 
    {
        self.yellowKeyPrice = 10;
        self.blueKeyPrice = 50;
        self.redKeyPrice = 100;
        [introduction setString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你"];
    }
    else
    {
        self.yellowKeyPrice = 5;
        self.blueKeyPrice = 25;
        self.redKeyPrice = 50;
        [introduction setString:@"勇士你好,若是你有多餘的鑰你能夠賣給我"];
    }
    [Key1Lable setString:[NSString stringWithFormat:@"黃鑰匙(%d)",self.yellowKeyPrice]];
    [Key2Lable setString:[NSString stringWithFormat:@"藍鑰匙(%d)",self.blueKeyPrice]];
    [Key3Lable setString:[NSString stringWithFormat:@"紅鑰匙(%d)",self.redKeyPrice]];
    [self removeChild:self.selSprite cleanup:YES];
    id blink = [CCBlink actionWithDuration:2 blinks:2];
    [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]];
    [self addChild:self.selSprite];
    self.selSprite.position = Key1Lable.position;
}
-(id)init
{
    if ((self = [super init])) 
    {
        //獲取屏幕大小
        CGSize size = [[CCDirector sharedDirector] winSize];
        self.selSprite = [CCSprite spriteWithFile:@"logo_select.png"];
        self.selSprite.scaleX = 2.0;
        id blink = [CCBlink actionWithDuration:2 blinks:2];
        [self.selSprite runAction:[CCRepeatForever actionWithAction:blink]];
        self.selID = 0;
        //背景
        CCTMXTiledMap *background = [CCTMXTiledMap tiledMapWithTMXFile:@"shopbg.tmx"];
        background.scale = 2.0;
        background.position = ccp(35, size.height / 2 - 200);
        [self addChild:background];
        //介紹標籤
        //introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你" fontName:@"Verdana-Bold" fontSize:30];
        introduction = [[CCLabelTTF alloc] initWithString:@"勇士你好,我這裏有各類鑰匙若是你有錢我能夠賣給你" dimensions:CGSizeMake(500, 100) alignment:UITextAlignmentCenter fontName:@"Verdana-Bold" fontSize:32];
        introduction.position = ccp(350, size.height - 200);
        [self addChild:introduction];
        //黃鑰匙標籤
        Key1Lable = [[CCLabelTTF alloc] initWithString:@"黃鑰匙(10)" fontName:@"Verdana-Bold" fontSize:30];
        Key1Lable.position = ccp(350, size.height - 260);
        [self addChild:Key1Lable];
        //藍鑰匙標籤
        Key2Lable = [[CCLabelTTF alloc] initWithString:@"藍鑰匙(50)" fontName:@"Verdana-Bold" fontSize:30];
        Key2Lable.position = ccp(350, size.height - 320);
        [self addChild:Key2Lable];
        //紅鑰匙標籤
        Key3Lable = [[CCLabelTTF alloc] initWithString:@"紅鑰匙(100)" fontName:@"Verdana-Bold" fontSize:30];
        Key3Lable.position = ccp(350, size.height - 380);
        [self addChild:Key3Lable];
        //離開商店
        exitShop = [[CCLabelTTF alloc] initWithString:@"離開商店" fontName:@"Verdana-Bold" fontSize:30];
        exitShop.position = ccp(350, size.height - 440);
        [self addChild:exitShop];
        //肯定
        enter = [[CCLabelTTF alloc] initWithString:@"肯定" fontName:@"Verdana-Bold" fontSize:30];
        enter.position = ccp(350,size.height - 500);
        [self addChild:enter];
        [self addChild:self.selSprite];
        self.selSprite.position = Key1Lable.position;
    }
    return self;
}
@end


好了這兩個類都有了,那麼就讓咱們添加Game01.m裏面的代碼吧

此次咱們要添加到if(npc_tileGid)裏面:

  1. case 4: 
  2.      business = [[Business alloc] initWithID:type]; 
  3.      business.isOnShop = YES
  4.      [self addChild:business]; 
  5.      break; 
  6. case 5: 
  7.      [buykey viewInit:5]; 
  8.      [self addChild:buykey]; 
  9.      buykey.isOnShop = YES
  10.      break; 
  11. case 6: 
  12.      [buykey viewInit:6]; 
  13.      [self addChild:buykey]; 
  14.      buykey.isOnShop = YES
  15.      break; 
  16. case 7: 
  17.      business = [[Business alloc] initWithID:type]; 
  18.      business.isOnShop = YES
  19.      [self addChild:business]; 
  20.      break; 

case 4:
     business = [[Business alloc] initWithID:type];
     business.isOnShop = YES;
     [self addChild:business];
     break;
case 5:
     [buykey viewInit:5];
     [self addChild:buykey];
     buykey.isOnShop = YES;
     break;
case 6:
     [buykey viewInit:6];
     [self addChild:buykey];
     buykey.isOnShop = YES;
     break;
case 7:
     business = [[Business alloc] initWithID:type];
     business.isOnShop = YES;
     [self addChild:business];
     break;


這樣咱們的「可用」npc又多了幾個,以後咱們會繼續完善咱們的npc,好了繼續添加咱們的代碼:

  1. if (business.isOnShop)  
  2.     { 
  3.         for (int i = 0; i <= 4; i++)  
  4.         { 
  5.             CGRect Rect1 = CGRectMake(200, 
  6.                                       size.height - 290 - i*60, 
  7.                                       400, 
  8.                                       60); 
  9.             //檢測觸點是否在控件區 
  10.             if (CGRectIntersectsRect(Rect, Rect1)) 
  11.             { 
  12.                 if (i == 4)  
  13.                 { 
  14.                     if (herohp.Experience >= business.curExperience2)  
  15.                     { 
  16.                         switch (business.selID) 
  17.                         { 
  18.                             case 0: 
  19.                                 if (herohp.Experience >= business.curExperience)  
  20.                                 { 
  21.                                     _hero.HP += 1000*business.curUpgrade; 
  22.                                     _hero.Attack += 7*business.curUpgrade; 
  23.                                     _hero.Defense += 7*business.curUpgrade; 
  24.                                     herohp.Grade += 1; 
  25.                                     [herohp updateGrade]; 
  26.                                     herohp.Experience -= business.curExperience; 
  27.                                 } 
  28.                                 break; 
  29.                             case 1: 
  30.                                 if (herohp.Experience >= business.curExperience2) 
  31.                                 { 
  32.                                     _hero.Attack += business.curAttack; 
  33.                                     herohp.Experience -= business.curExperience2; 
  34.                                 } 
  35.                                 break; 
  36.                             case 2: 
  37.                                 if (herohp.Experience >= business.curExperience2) 
  38.                                 { 
  39.                                     _hero.Defense += business.curDefense; 
  40.                                     herohp.Experience -= business.curExperience2; 
  41.                                 } 
  42.                                 break; 
  43.                             default: 
  44.                                 break; 
  45.                         } 
  46.                         [herohp updateHeroHp]; 
  47.                         [herohp updateHeroAttack]; 
  48.                         [herohp updateHeroDefense]; 
  49.                         [herohp updateExperience]; 
  50.                     } 
  51.                 } 
  52.                 else if (i == 3)  
  53.                 { 
  54.                     _hero.isFighting = NO
  55.                     business.isOnShop = NO
  56.                     [self removeChild:business cleanup:YES]; 
  57.                 } 
  58.                 else 
  59.                     business.selID = i
  60.                 if (i<3)  
  61.                 { 
  62.                     business.selSprite.position = ccp(350, size.height - 260 - i*60); 
  63.                 } 
  64.             } 
  65.         } 
  66.     } 
  67.     if (buykey.isOnShop)  
  68.     { 
  69.         for (int i = 0; i <= 4; i++)  
  70.         { 
  71.             CGRect Rect1 = CGRectMake(200, 
  72.                                       size.height - 290 - i*60, 
  73.                                       400, 
  74.                                       60); 
  75.             //檢測觸點是否在控件區 
  76.             if (CGRectIntersectsRect(Rect, Rect1)) 
  77.             { 
  78.                 if (i == 4)  
  79.                 { 
  80.                     switch (buykey.selID)  
  81.                     { 
  82.                         case 0: 
  83.                             if (buykey.yellowKeyPrice > 5)  
  84.                             { 
  85.                                 if (herohp.Coin >= 10)  
  86.                                 { 
  87.                                     herohp.Coin -= 10
  88.                                     herohp.YellowKey += 1; 
  89.                                 } 
  90.                             } 
  91.                             else 
  92.                             { 
  93.                                 herohp.Coin += 5; 
  94.                                 herohp.YellowKey -= 1;   
  95.                             }   
  96.                             break; 
  97.                         case 1: 
  98.                             if (buykey.yellowKeyPrice > 5)  
  99.                             { 
  100.                                 if (herohp.Coin >= 50)  
  101.                                 { 
  102.                                     herohp.Coin -= 50
  103.                                     herohp.BlueKey += 1; 
  104.                                 } 
  105.                             } 
  106.                             else 
  107.                             { 
  108.                                 herohp.Coin += 25; 
  109.                                 herohp.BlueKey -= 1;   
  110.                             } 
  111.                             break; 
  112.                         case 2: 
  113.                             if (buykey.yellowKeyPrice > 5)  
  114.                             { 
  115.                                 if (herohp.Coin >= 100)  
  116.                                 { 
  117.                                     herohp.Coin -= 100
  118.                                     herohp.RedKey += 1; 
  119.                                 } 
  120.                             } 
  121.                             else 
  122.                             { 
  123.                                 herohp.Coin += 50; 
  124.                                 herohp.RedKey -= 1;   
  125.                             } 
  126.                             break; 
  127.                         default: 
  128.                             break; 
  129.                     } 
  130.                     [herohp updateCoin]; 
  131.                     [herohp updateKey1]; 
  132.                 } 
  133.                 else if (i == 3)  
  134.                 { 
  135.                     _hero.isFighting = NO
  136.                     buykey.isOnShop = NO
  137.                     [self removeChild:buykey cleanup:YES]; 
  138.                 } 
  139.                 else 
  140.                 { 
  141.                     buykey.selID = i
  142.                 } 
  143.                 if (i<3)  
  144.                 { 
  145.                     buykey.selSprite.position = ccp(350, size.height - 260 - i*60); 
  146.                 } 
  147.             } 
  148.         } 
  149.          
  150.     } 

if (business.isOnShop) 
    {
        for (int i = 0; i <= 4; i++) 
        {
            CGRect Rect1 = CGRectMake(200,
                                      size.height - 290 - i*60,
                                      400,
                                      60);
            //檢測觸點是否在控件區
            if (CGRectIntersectsRect(Rect, Rect1))
            {
                if (i == 4) 
                {
                    if (herohp.Experience >= business.curExperience2) 
                    {
                        switch (business.selID)
                        {
                            case 0:
                                if (herohp.Experience >= business.curExperience) 
                                {
                                    _hero.HP += 1000*business.curUpgrade;
                                    _hero.Attack += 7*business.curUpgrade;
                                    _hero.Defense += 7*business.curUpgrade;
                                    herohp.Grade += 1;
                                    [herohp updateGrade];
                                    herohp.Experience -= business.curExperience;
                                }
                                break;
                            case 1:
                                if (herohp.Experience >= business.curExperience2)
                                {
                                    _hero.Attack += business.curAttack;
                                    herohp.Experience -= business.curExperience2;
                                }
                                break;
                            case 2:
                                if (herohp.Experience >= business.curExperience2)
                                {
                                    _hero.Defense += business.curDefense;
                                    herohp.Experience -= business.curExperience2;
                                }
                                break;
                            default:
                                break;
                        }
                        [herohp updateHeroHp];
                        [herohp updateHeroAttack];
                        [herohp updateHeroDefense];
                        [herohp updateExperience];
                    }
                }
                else if (i == 3) 
                {
                    _hero.isFighting = NO;
                    business.isOnShop = NO;
                    [self removeChild:business cleanup:YES];
                }
                else
                    business.selID = i;
                if (i<3) 
                {
                    business.selSprite.position = ccp(350, size.height - 260 - i*60);
                }
            }
        }
    }
    if (buykey.isOnShop) 
    {
        for (int i = 0; i <= 4; i++) 
        {
            CGRect Rect1 = CGRectMake(200,
                                      size.height - 290 - i*60,
                                      400,
                                      60);
            //檢測觸點是否在控件區
            if (CGRectIntersectsRect(Rect, Rect1))
            {
                if (i == 4) 
                {
                    switch (buykey.selID) 
                    {
                        case 0:
                            if (buykey.yellowKeyPrice > 5) 
                            {
                                if (herohp.Coin >= 10) 
                                {
                                    herohp.Coin -= 10;
                                    herohp.YellowKey += 1;
                                }
                            }
                            else
                            {
                                herohp.Coin += 5;
                                herohp.YellowKey -= 1;  
                            }  
                            break;
                        case 1:
                            if (buykey.yellowKeyPrice > 5) 
                            {
                                if (herohp.Coin >= 50) 
                                {
                                    herohp.Coin -= 50;
                                    herohp.BlueKey += 1;
                                }
                            }
                            else
                            {
                                herohp.Coin += 25;
                                herohp.BlueKey -= 1;  
                            }
                            break;
                        case 2:
                            if (buykey.yellowKeyPrice > 5) 
                            {
                                if (herohp.Coin >= 100) 
                                {
                                    herohp.Coin -= 100;
                                    herohp.RedKey += 1;
                                }
                            }
                            else
                            {
                                herohp.Coin += 50;
                                herohp.RedKey -= 1;  
                            }
                            break;
                        default:
                            break;
                    }
                    [herohp updateCoin];
                    [herohp updateKey1];
                }
                else if (i == 3) 
                {
                    _hero.isFighting = NO;
                    buykey.isOnShop = NO;
                    [self removeChild:buykey cleanup:YES];
                }
                else
                {
                    buykey.selID = i;
                }
                if (i<3) 
                {
                    buykey.selSprite.position = ccp(350, size.height - 260 - i*60);
                }
            }
        }
        
    }


好了運行一下試試吧!

在這裏我要感謝這幾天你們對個人支持,大家的支持是我最大的動力!

還有請轉載我文章的朋友們注意添加原文鏈接,謝謝!

在這裏我補充一點內容就是以前的代碼中鑰匙商店沒有初始化,咱們須要在

Game01.m初始化方法中添加buykey = [[Buykey alloc] init];這樣就好了。

相關文章
相關標籤/搜索