I have a project in which I am trying to implement a pathfinding class but I have stumbled upon an issue I can't seem to fix.
A video of the error as it occurs can be found here: https://www.dropbox.com/s/25ajb0mc5p4a3a9/Tilemap%20Error.mov
The error message thrown is: Assertion failure in -[CCTMXLayer tileGIDAt:withFlags:], /Users/Dave/Desktop/AI_DISS_new copy/AI_DISS/libs/cocos2d/CCTMXLayer.m:304
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'TMXLayer: invalid position'.
The point returns as pixel values while the map and layer sizes return in tile values so I tried dividing variables holding pixel values by the width or height of the tiles but nothing seems to have worked.
GID for tileAt:point returns too high when using pixel values (understandably) and when converted to tile values, searches for a very long time, eventually moving off the map and continuously searching until Xcode crashes.
I have tried to explain in as much detail as possible I apologize if this isn't the kind of question best suited to this forum. I would really appreciate any assistance.
If you need further details please ask.
The original instructions for using the class were on cocos2d forums which have just had an overhaul and the thread appears to have been moved or deleted so I can't quote them but I am sure the tilemap (a TMX Tilemap) and layer attributes have been passed in correctly.
From my HelloWorldLayer class the values are:
//Pathfinding related code
////////////////////////////
_tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"NewMap.tmx"];
_pathFinder = [[AStar alloc] initWithTileMap:_tileMap groundLayer:@"Collision"]; //collidable Tiles
[_pathFinder setCollideKey:@"Collidable"]; // defaults to COLLIDE
[_pathFinder setCollideValue:@"True"]; // defaults to 1
_pathFinder2 = [[AStar alloc] initWithTileMap:_tileMap groundLayer:@"Collision"]; //collidable Tiles
[_pathFinder2 setCollideKey:@"Collidable"]; // defaults to COLLIDE
[_pathFinder2 setCollideValue:@"True"]; // defaults to 1
/////////////////////////////
and the move method is called as:
/////////////// player path finding related code //////////////////
[_pathFinder moveSprite:_player from:s to:f atSpeed:0.003];
///////////// end player path finding related code //////////////
Thanks in advance.
GID Code as commented on below:
if (tileGid)
{
// check the tile for the collide property.
NSDictionary *dict = [tileMap propertiesForGID:tileGid];
if (dict)
{
//check the tile for the collideKey and return Yes if a match
NSString *collide = [dict valueForKey:collideKey];
if (collide && [collide compare:collideValue] == NSOrderedSame)
return YES;
}
}