我一直在尝试获取我的数组计数,但它一直返回 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]);
}
}
}
}