cocos2d-x读取TMX文件的疑惑

  • 本帖最后由 start4u 于 2013-7-1 09:38 编辑 *

我的TMX文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="50" height="50" tilewidth="32" tileheight="32">
 <tileset firstgid="1" name="tmw_desert_spacing" tilewidth="32" tileheight="32" spacing="1" margin="1">
  <image source="tmw_desert_spacing.png" width="265" height="199"/>
 </tileset>
 <layer name="Background" width="50" height="50">
  <data encoding="base64" compression="zlib">
   eJztl0sOwyAMRDlJanVRZdXe/3bdZIEQn7FDbVBn8SSUIGWeDQocKaXj4szG/0x0HfLvP41E17DEksnTQzbykEZe1KG2rrTz7u4RqYxbXr/iM6kXSG9qtGr4DvQo83v2Y6YD0itLb3q8LmZ49LJ69OSuC5rRw8UDjW+vv713K7mM5ow8CSEYjwHR+azkZ8qVPU6A6IyoR6v+patXJkn2cxly1/V20Xho7+orulgyee8XAXx28EDyrL6uNHlaubTPIx3yvqBZPTwkYXu8lmW3/95qa4MehBBCCCGEEEJILF+5RSf/
  </data>
 </layer>
 <objectgroup name="Objects" width="50" height="50">
  <object name="SpawnPoint" x="35" y="358" width="27" height="20"/>
 </objectgroup>
</map>

读取TMX放在INIT函数中,代码如下:

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    tileMap = CCTMXTiledMap::create("TileMap.tmx");
    background = tileMap->layerNamed("Background");
    
    CCTMXObjectGroup *objectGroup = tileMap->objectGroupNamed("Objects");
    
    CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
    
    float x = ((CCString *)spawnPoint->objectForKey("x"))->floatValue();
    float y = ((CCString *)spawnPoint->objectForKey("y"))->floatValue();
    
    return true;
}

上面取出来的x值是35这是对的,但是y为什么取出来是1222,理论应该是358,我实在弄不明白,有没有人帮忙看看,谢谢

int y = ((CCString*)dict->objectForKey(key))->intValue();
楼主这样试试…