您当前的位置: 首页 >  游戏

Cocos2D:塔防游戏制作之旅(五)

发布时间:2015-11-16 21:20:01 ,浏览量:0

打开HelloWorldLayer.h文件,添加以下实例变量(在@interface行的花括号之后):

NSMutableArray *towerBases;

将HelloWorldLayer.m文件修改为如下内容:

//Add a new method  -(void)loadTowerPositions
{ NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"TowersPosition" ofType:@"plist"]; NSArray * towerPositions = [NSArray arrayWithContentsOfFile:plistPath];
    towerBases = [[NSMutableArray alloc] initWithCapacity:10]; for(NSDictionary * towerPos in towerPositions)
    {
        CCSprite * towerBase = [CCSprite spriteWithFile:@"open_spot.png"];
        [self addChild:towerBase];
        [towerBase setPosition:ccp([[towerPos objectForKey:@"x"] intValue],
                                   [[towerPos objectForKey:@"y"] intValue])];
        [towerBases addObject:towerBase];
    }

} //In init, call this new method in section #3 // 3 - Load tower positions [self loadTowerPositions];

编译运行app,你将看到道路周围的矩形底座,它们充当了玩家炮塔的基座.

这里写图片描述

现在炮塔基座已经就绪,号召我们建立装备和建立炮塔!

首先,打开HelloWorldLayer.h文件,添加一个属性(在闭花括号之后):

@property (nonatomic,strong) NSMutableArray *towers;

在HelloWorldLayer.m中@implementation行下面同步towers属性:

@synthesize towers;
在高版本的Xcode中同步属性已经不再需要.(猫猪注)
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    110453博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0522s