我有两个数组(一个存储整数和另一个存储点)。
CCArray* getSSEdgeCode;
CCArray* getSSTileCode;
创建数组:
-(void) storeTilePointData:(CGPoint) edgePt tileCode:(int) tileCd
{
if ([getSSTileCode count] < [getSSTileCode capacity])
{
[posTile addObject:[NSValue valueWithCGPoint: edgePt]];
[getSSTileCode addObject:[NSNumber numberWithInt: tileCd]];
}
}
在访问之前打印阵列:
for (int j=0; j<[getSSTileCode count]; j++)
CCLOG(@"for ss %d: tileCode: %@ position: %@", j, [getSSTileCode objectAtIndex:j], [posTile objectAtIndex:j]);
CCLOG的输出:
对于ss 0:tileCode:11位置:NSPoint:{70,315}
对于ss 1:tileCode:12位置:NSPoint:{160,315}
for ss 2:tileCode:13 position:NSPoint:{250,315}
for ss 3:tileCode:21 position:NSPoint:{70,225}
for ss 4:tileCode:22 position:NSPoint:{160,225}
对于ss 5:tileCode:23位置:NSPoint:{250,225}
对于ss 6:tileCode:31位置:NSPoint:{70,135}
对于ss 7:tileCode:32位置:NSPoint:{160,135}
对于ss 8:tileCode:33位置:NSPoint:{250,135}
当我搜索数组时,我找到前两个(tilecodes 11&amp; 12),但不是其他任何一个:
-(CGPoint) tilePosition:(int) tileCode
{
CGPoint pos;
NSNumber* n = [NSNumber numberWithInt:tileCode];
if ([getSSTileCode containsObject:n])
{
int i = [getSSTileCode indexOfObject: n];
pos = [[posTile objectAtIndex:i] CGPointValue];
}
else
pos = CGPointMake(0, 0);
return pos;
}
我已尝试使用numberWithInt和numberWithInteger获得相同的结果。
有什么想法吗?