타일이있는 QT로 만든 타일 맵이 몇 개 있으며이 맵의 객체 그룹을 기반으로 CGpoint ** 배열을 만들려고합니다 (Waypoint라고 부름).동적 CGPoint ** 배열을 만드는 방법
각지도에는 경로라고하는 몇 개의 경유지가있을 수 있습니다.
//Create the first dimension
int nbrOfPaths = [[self.tileMap objectGroups] count];
CGPoint **pathArray = malloc(nbrOfPaths * sizeof(CGPoint *));
그런
//Create the second dimension
int pathCounter = 0;
while ((path = [self.tileMap objectGroupNamed:[NSString stringWithFormat:@"Path%d", pathCounter]])) {
int nbrOfWpts = 0;
while ((waypoint = [path objectNamed:[NSString stringWithFormat:@"Wpt%d", nbrOfWpts]])) {
nbrOfWpts++;
}
pathArray[pathCounter] = malloc(nbrOfWpts * sizeof(CGPoint));
pathCounter++;
}
지금 내가 NSLog ("%의 @"@ pathArray가), 그것은 나를 보여줍니다 때 pathArray
//Fill the array
pathCounter = 0;
while ((path = [self.tileMap objectGroupNamed:[NSString stringWithFormat:@"Path%d", pathCounter]]))
{
int waypointCounter = 0;
//Get all the waypoints from the path
while ((waypoint = [path objectNamed:[NSString stringWithFormat:@"Wpt%d", waypointCounter]]))
{
pathArray[pathCounter][waypointCounter].x = [[waypoint valueForKey:@"x"] intValue];
pathArray[pathCounter][waypointCounter].y = [[waypoint valueForKey:@"y"] intValue];
NSLog(@"x : %f & y : %f",pathArray[pathCounter][waypointCounter].x,pathArray[pathCounter][waypointCounter].y);
waypointCounter++;
}
pathCounter++;
}
을 채우려
두 번째 차원에 전체 pathArray가 x와 y가됩니다.그러나이 이 문제 :
y 값이 (x 값이 올바른지 내 tilemap.tmx이 너무 정확)
<object name="Wpt0" x="-18" y="304"/> <-- I get x : -18 and y :336 with NSLog <object name="Wpt1" x="111" y="304"/> <-- I get x : 111 and y :336 <object name="Wpt2" x="112" y="207"/> <-- I get x : 112 and y :433
가 나는 EX_BAD_ACCESS을 얻을 결코 올바른 NSLog 끝 부분에서
EDIT CGPoint와 관련된 NSLog (% @)에 감사드립니다. 이 객체가 아니기 때문에 당신이 그런 NSLog CGPoint 수없는, 모든
NSLog(@"x : %f & y : %f",pathArray[pathCounter][waypointCounter].x,pathArray[pathCounter][waypointCounter].y);
올바른 코드입니다. 'NSLog'에 대한 정확한 호출을 보여줄 수 있습니까? '% @'지정자를 사용하여'pathArray'를 인쇄하려하지 않습니다. 맞습니까? 이 지정자는 객체를위한 것이기 때문에'pathArray'는 C 배열입니다. 그것을 채우기 위해 사용한 두 개의 중첩 된 루프 배열을 사용하여 이동해야합니다. – dasblinkenlight