I am attempting to add this tiled map to my project. I noticed that if I have a layer in the tiled file I can simply do this
tileMap = cocos2d::TMXTiledMap::create("sandbox.tmx");
tileMap->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
Now I have this tiled file that came with the tiled software. The tiled file is located here.
As you can see this tiled file does not have any layers init and all the content in the file are basically objects inside object groups.I know we can iterate through the object collection using the code. However from the file you can see that the object group "ground" has multiple objects in it, I would like to display those objects.
TMXTiledMap *tileMap = TMXTiledMap::create("sandbox.tmx");
auto group = tileMap->getObjectGroup("ground");
auto& objects = group->getObjects();
Value objectsVal = Value(objects);
for (auto& obj : objects)
ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat();
float y = dict["y"].asFloat();
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
// Add sprites here manually
??? How do I add this object to the layer.
My question is how do I add the objects in the ground object group to my layer ? Is that possible or will I have to copy them to my layer first ?