0
我需要爲我的精靈座標數組創建一個數組,並且我想要在精靈具有從數組座標時移除座標,因爲我不想讓另一個精靈擁有同樣的座標,我似乎無法得到它的工作,沒有錯誤,並在調試時說,nsexception並退出。我做錯了什麼,我在哪裏取消分配數組?當我釋放他們dealloc它說我需要申報他們。從數組中移除整數
CGPoint cg1 = CGPointMake(33,33);
NSValue *cg1obj = [NSValue valueWithCGPoint:cg1];
CGPoint cg2 = CGPointMake(33,97);
NSValue *cg2obj = [NSValue valueWithCGPoint:cg2];
NSMutableArray *numberxy = [[NSMutableArray alloc] init]; int pointcount = 0;
[numberxy insertObject:cg1obj atIndex:pointcount++];
[numberxy insertObject:cg2obj atIndex:pointcount++];
NSMutableArray *sprites = [[NSMutableArray alloc] init]; int spritecount = 0;
[sprites insertObject:red1 atIndex:spritecount++];
[sprites insertObject:red2 atIndex:spritecount++];
for (int i=0; i<3;i++) {
int rpoint = arc4random() % 3;
int rsprite = arc4random() % 3;
CGPoint point = [[numberxy objectAtIndex:rpoint] CGPointValue];
CCSprite *sprite1 = [sprites objectAtIndex:rsprite];
sprite1.position = ccp(point.x,point.y);
if (sprite1.position.x == point.x && sprite1.position.y == point.y) {
[numberxy removeObjectAtIndex:rpoint];
[sprites removeObjectAtIndex:rsprite];
}
}
不奇怪 - 廢話。 Dangermouse的代碼沒有任何意義,並且表示對對象引用的指針缺乏理解。我的建議是閱讀Objective-C指南,然後在該代碼上播放計算機;解釋每行代碼的作用。 – bbum 2011-01-27 17:43:47