Hi,
I want to try tiled map with a tmx file, I put the map.tmx
file under ${PROJECT_FOLDER}/Resources/map/map.tmx
And used it like this:
void HelloWorld::addMap() {
map = TMXTiledMap::create("map/map.tmx");
this->addChild(map, -1, -1);
mapLayer = map->layerNamed("Grids");
this->setUp();
}
But when building there is a TMXTiledMap: Map not found
exception thrown out.
What I have done wrong?
Hi, I found that the layer get by tmap->getLayer("layerName")
returns a null value
So far I have tried csv format and base64(uncompressed) format, but both are null
Here is the code to getLayer:
auto tmap = TMXTiledMap::create("map/map.tmx");
auto layer = tmap->getLayer("gamemap");
auto size = tmap->getMapSize();
CCLOG(" %f, %f", size.height, size.width);
auto sprite = layer->getTileAt(Vec2(1, 1));
And here is the tmx
file
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.0.2" orientation="orthogonal" renderorder="right-down" width="7" height="7" tilewidth="100" tileheight="100" nextobjectid="1">
<tileset firstgid="1" source="map.tsx"/>
<layer name="gamemap" width="7" height="7">
<data>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="2"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
</data>
</layer>
</map>
try running a tiled example first
I have found this out that not only I should put the tmx
file in the source folder but also I have to import tileset file tsx
file in the same folder and as well as the image that I loaded as a tileset file too. but the error message could be a mis-leading for the solution
1 Like