打开HelloWorldLayer.h文件,添加以下实例变量(在@interface行的花括号之后):
NSMutableArray *towerBases@H_301_5@;
//Add a new method @H_301_5@
-(void@H_301_5@)loadTowerPositions
{
NSString@H_301_5@* plistPath = [[NSBundle@H_301_5@ mainBundle] pathForResource:@"TowersPosition"@H_301_5@ ofType:@"plist"@H_301_5@];
NSArray@H_301_5@ * towerPositions = [NSArray@H_301_5@ arrayWithContentsOfFile:plistPath];
towerBases = [[NSMutableArray@H_301_5@ alloc] initWithCapacity:10@H_301_5@];
for@H_301_5@(NSDictionary@H_301_5@ * towerPos in towerPositions)
{
CCSprite * towerBase = [CCSprite spriteWithFile:@"open_spot.png"@H_301_5@];
[self@H_301_5@ addChild:towerBase];
[towerBase setPosition:ccp([[towerPos objectForKey:@"x"@H_301_5@] intValue],[[towerPos objectForKey:@"y"@H_301_5@] intValue])];
[towerBases addObject:towerBase];
}
}
//In init,call this new method in section #3@H_301_5@
// 3 - Load tower positions@H_301_5@
[self@H_301_5@ loadTowerPositions];
编译运行app,你将看到道路周围的矩形底座,它们充当了玩家炮塔的基座.
现在炮塔基座已经就绪,号召我们建立装备和建立炮塔!
首先,打开HelloWorldLayer.h文件,添加一个属性(在闭花括号之后):
@property@H_301_5@ (nonatomic@H_301_5@,strong@H_301_5@) NSMutableArray@H_301_5@ *towers;
在HelloWorldLayer.m中@implementation行下面同步towers属性:
@synthesize@H_301_5@ towers@H_301_5@;
在高版本的Xcode中同步属性已经不再需要.(猫猪注)