Tiled map not being displayed in a new hello world project

I am trying to load a tiled map to a hello world project. However I see nothing of the tiled on the simulator - this is what the code looks like

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
	
 
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	
	//Load paths
	std::vector<std::string> searchPaths;
	searchPaths.push_back("/Users/zedan/Development/TestCpp/Resources/content/");
	FileUtils::getInstance()->setSearchPaths(searchPaths);
	
	cocos2d::TMXTiledMap* tileMap;
	tileMap = cocos2d::TMXTiledMap::create("sandbox.tmx");

	//tileMap->setPosition(Vec2(0,0));
	tileMap->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
	this->addChild(tileMap);
	
    return true;
	
}

The tiled map came as an example with the tiled app. I could see the tileMap object has the objectGroups with content from the file however I dont see anything on the screen any suggestions.This is what the object layer content looks like in Tiled

Any suggestions on why I am not seeing anything on the screen ?

For Objects you have to fetch it and have to display manually.
For example:

TMXTiledMap *tileMap = TMXTiledMap::create("1.tmx");
this->addChild(tileMap, 20);

auto group = tileMap->getObjectGroup("Object Layer 1");
auto& objects = group->getObjects();

Value objectsVal = Value(objects);
log("%s", objectsVal.getDescription().c_str());

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
}
1 Like

Thanks Ill try this out and report back if it solves the problem.

How do I add obj to this Layer ?

You mean in Tiled editor?
You have to create ObjectLayer by clicking ‘Add Object Layer’ option.
and for code you can check in cpp-test also. TileMapTest

I just expanded on my question here