Add tiles at runtime

Hi

I want to let the user customise the game experience a little. Is there a way that I can update tile sets during runtime? I would like to add some new images during the game which are unique to each player to the tile map.

thanks HP

auto map = TMXTiledMap::create("MyMap.tmx");
auto myLayer = map->getLayer("MyLayer"); // get your tile Layer
myLayer->setTileGID(change_tile_gid, Vec2(tile_cooord));

Good idea @howlryu

HI

thanks for the idea, but that would assume that the sprite for the tile is already inside the tileset during development. This is the normal usecase.
In my case I want to load new sprites which the user creates into the tileset. So I am looking for a way to build custom tilesets for each user.

HP

I think you should create your own TMXLayer manually.
TMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);

or you can make your own parser, or builder use Tmx Map format.

How about use TMXGenerator?


It helps edit map, and generate xml file.
like this,

  1. Load your map or create a new one
    CCTMXTiledMap* mymap = CCTMXTiledMap::create(“level01.tmx”);
  2. Edit map
  3. Generate XML
    std::string xml_output = generateXMLForTMXTiledMap(mymap);
  4. Write XML file or store in database

I think the last one is the best choice.