【发布时间】:2013-04-24 08:37:13
【问题描述】:
我正在做的是在“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