【发布时间】:2013-03-05 01:02:43
【问题描述】:
我一直在尝试获取我的数组计数,但它一直返回 0,我认为它没有正确添加对象。我将我的属性放在头文件中并在 layer.m 文件中合成它。我在我的超级初始化中分配了空间。
NSMutableArray *asteroids;
@property (strong) NSMutableArray *asteroids;
@synthesize asteroids;
self.asteroids = [[NSMutableArray alloc] init];
-(void)findTiles
{
CGPoint tilecoord1;
int tileGid1;
int aheadcount = 200;
CCSprite *tileonPos[aheadcount];
int amounts = 0;
for(int x = 0; x<30; x++)
{
for(int y = 0; y<20; y++)
{
tilecoord1 = ccp(x+(480*currentlevel),y);
tileGid1 = [bglayer tileGIDAt:tilecoord1];
if(tileGid1 == 1)
{
tileonPos[amounts] = [bglayer tileAt:ccp(x,y)];
amounts++;
[asteroids addObject:tileonPos[amounts]];
NSLog(@"%d",[asteroids count]);
}
}
}
}
【问题讨论】:
-
首先检查这段代码是否通过了 if 语句。
tileGid1 == 1可能永远不会评估为 TRUE (YES)。我假设您已经将定义和启动分开了!
标签: objective-c nsmutablearray