“图块地图没有对象对象图层”当对象图层有对象时

时间:2013-04-24 08:37:14

标签: ios objective-c xcode cocos2d-iphone

Im doing this tutorial

我正在做的是在“Tiled”制作瓷砖地图,你知道人们可能知道我在说什么。我已经按照教程中的每一步进行操作,但是,当我构建并运行时,应用程序会在加载屏幕后立即崩溃。它崩溃了错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'tile map has no objects object layer'

或者,对于断点,它会在:

处中断
NSAssert(objectGroup != nil, @"tile map has no objects object layer");

我将自己的.tmx文件与教程下载中的文件进行了比较,并且它们匹配起来。 相关的.tmx代码:

<objectgroup name="Objects" width="15" height="13">
<object name="SpawnPoint" x="35" y="36"/>
</objectgroup>

你会认为这算作对象层中的对象,对吗?我确定SpawnPoint对象位于Tiled中的正确层中。 这是我的init方法(应用程序崩溃的方法):

-(id) init
{
if( (self=[super init]) ) {
    CCTMXObjectGroup *objectGroup = [_tileMap objectGroupNamed:@"Objects"];
    NSAssert(objectGroup != nil, @"tile map has no objects object layer");

    NSDictionary *spawnPoint = [objectGroup objectNamed:@"SpawnPoint"];
    int x = [spawnPoint[@"x"] integerValue];
    int y = [spawnPoint[@"y"] integerValue];

    _player = [CCSprite spriteWithFile:@"player.png"];
    _player.position = ccp(x,y);

    [self addChild:_player];

    self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"TileBomb.tmx"];
    self.background = [_tileMap layerNamed:@"Background"];
    self.meta = [_tileMap layerNamed:@"Meta"];
    _meta.visible = NO;
    [self addChild:_tileMap z:-1];
    self.touchEnabled = YES;


}
return self;
}

有谁理解为什么会这样?&amp;怎么解决?

1 个答案:

答案 0 :(得分:1)

解决了它。在使用文档之前始终获取文档。 init方法在导入之前从tilemap中读取对象。留在这里作为参考对于那些与我同样不高兴的人

相关问题