【问题标题】:"Tile map has no objects object layer" When object layer has objects“平铺地图没有对象对象层”当对象层有对象时
【发布时间】:2013-04-24 08:37:13
【问题描述】:

Im doing this tutorial

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

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

有谁明白为什么会发生这种情况以及如何解决它?

【问题讨论】:

  • 你确定 _tileMap 不是 nil 吗?

标签: ios objective-c xcode cocos2d-iphone


【解决方案1】:

解决了。在使用文档之前,请务必获取文档。 init 方法在导入之前从 tilemap 中读取对象。把这个留在这里供和我一样笨的人参考

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2013-11-15
    • 2011-01-10
    相关资源
    最近更新 更多