0

我有一个项目,我正在尝试实现一个寻路类,但我偶然发现了一个我似乎无法解决的问题。

可以在此处找到错误发生时的视频: https ://www.dropbox.com/s/25ajb0mc5p4a3a9/Tilemap%20Error.mov

抛出的错误信息是: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'.

该点以像素值的形式返回,而地图和图层大小以平铺值的形式返回,因此我尝试将保存像素值的变量除以平铺的宽度或高度,但似乎没有任何效果。

tileAt:point 的 GID 在使用像素值时返回太高(可以理解),当转换为 tile 值时,搜索很长时间,最终离开地图并不断搜索,直到 Xcode 崩溃。

我已尝试尽可能详细地解释,如果这不是最适合本论坛的问题,我深表歉意。我真的很感激任何帮助。

如果您需要更多详细信息,请询问。

使用该类的原始说明在 cocos2d 论坛上,该论坛刚刚进行了大修,线程似乎已被移动或删除,所以我无法引用它们,但我确信 tilemap(一个 TMX Tilemap)和图层属性已经正确传入。

在我的 HelloWorldLayer 类中,值是:

    //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

    /////////////////////////////

并且 move 方法被称为:

/////////////// player path finding related code //////////////////
[_pathFinder moveSprite:_player from:s to:f atSpeed:0.003];
///////////// end player path finding related code //////////////

提前致谢。

GID 代码如下评论:

    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;
        }
    }
4

0 回答 0