2013-04-24 103 views
1

Im doing this tutorial「瓷磚映射沒有對象的對象層」當對象層對象

我在做什麼的「瓷磚」正在瓦片地圖,你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; 
} 

有誰知道爲什麼發生這種情況&如何解決呢?

+0

你確定_tileMap不是零嗎? – dqhendricks 2013-04-25 15:26:43

回答

1

解決了它。在使用文檔之前始終獲取文檔。 init方法在導入之前從tilemap中讀取對象。把這裏留下來供人們參考,就像我這樣的人同樣不怎麼樣