-(id) init
{
if((self=[super init])) {
_targets = [[NSMutableArray alloc] init];
temp = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4",nil];
tempArray = [[NSMutableArray alloc] initWithArray:temp];
resultArray = [[NSMutableArray alloc] init];
[self thelogic];
}
return self;
}
-(void)thelogic
{
int i;
int count = 4;
for (i = 0; i < 3; i ++) {
int index = arc4random() % (count - i);
[resultArray addObject:[tempArray objectAtIndex:index]];
CCSprite *target = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@.png", [tempArray objectAtIndex:index]]];
target.tag = [[NSString stringWithFormat:@"%@",[tempArray objectAtIndex:index]] integerValue];
[self addChild:target];
[_targets addObject:target];
[tempArray removeObjectAtIndex:index];
}
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[_targets removeAllObjects];
[self thelogic];
}
, 나는 세 가지 다른 번호를 얻을이 장면을 입력 할 때 서로 다른 이미지와 세 개의 스프라이트를 만들고, 나는 세 이전 스프라이트가 제거됩니다, 화면을 터치 할, 그리고 3 개의 새로운 스프라이트가 표시되지만, 업 코드는 항상 충돌하므로 어떻게 수정해야합니까? 감사에러 인덱스 위 코드에서
응용 프로그램이 충돌 할 때 정확한 오류 메시지를 게시하십시오. – sergio
@ 오류 오류 메시지는 '*** - [NSArrayM objectAtIndex :] : 경계 3 초과 [0 .. 0]', 감사합니다 – matt