"볼"에 가장 가까운 "플레이어"를 찾으려고하고 있으며이 각각의 객체는 CCSprite 객체입니다. 이것은 내 첫 번째 응용 프로그램입니다, 그래서이 할 수있는 더 좋은 방법이 있다면, 그것은 여기가장 가까운 CCSprite 찾기
을 :) 지금까지 내 코드의 제안 주시기 :
for(CCSprite *currentPlayer in players) {
// distance formula
CGFloat dx = ball.position.x - currentPlayer.position.x;
CGFloat dy = ball.position.y - currentPlayer.position.y;
CGFloat distance = sqrt(dx*dx + dy*dy);
// add the distance to the distances array
[distances addObject:[NSNumber numberWithFloat:distance]];
NSLog(@"This happen be 5 times before the breakpoint");
NSLog(@"%@", [NSNumber numberWithInt:distance]);
}
그래서이 잘 작동하는 것 같다; 그것은 볼에서 플레이어의 각 거리를 기록합니다. 그러나 나는 이런 내 "거리"배열을 루프, 때
for(NSNumber *distance in distances) {
NSLog(@"Distance loop");
NSLog(@"%@", [NSNumber numberWithInt:distance]);
}
그리고이 220255312.처럼, 때마다 엄청난 수 로깅 내가 이렇게 내 거리의 배열을 선언 :
// setting the distance array
NSMutableArray *distances = [[NSMutableArray alloc] init];
내가 도대체 뭘 잘못하고있는 겁니까?
시간 내 주셔서 감사합니다. 이 같은 @ "%의 @"에 대한
도움이되었습니다. 내가 올바른 값을 가지고있는 것 같아, 환호 Mikey! –