How to add tiledmap to visual studio project

Hi,

I created a game project in visual studio. I have added tmx and the png file to assets/resource folder.
But when I use the following code then map variable is null, any idea what can go wrong.

auto map = TMXTiledMap::create("TiledMap.tmx"); // map is null
addChild(map, 0, 100);

It looks TiledMap.tmx is not found when I am running the app in WP8 emulator, when the app is installed to emulator, then the tiled map should be installed also. If I add a simple png file to create a sprite then it looks it is fine.
I saw the cocos2d-x example working fine. But not sure what extra should be done.
Thanks for help.

I have copied the 2 files (tmx and png) files to Assets\Resources. I have added (by add | existing items) two files to the projects. When TMXTiledMap::create() is called then this files is not found (for some reason)

Hi, try this:

std::string file = "map.tmx";
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
this->_tileMap = TMXTiledMap::createWithXML(str->getCString(),"");
addChild(_tileMap, 1);

Hi,
Thanks for reply.
It looks it has the same effect. While I was trying to make it working, I progressed little bit.
If I check the properties of tmx file then there is an option “Copy to output directory” if I change it to “Copy if never” or “Copy always” then my app find the file but showing another problem, it shows an access violation.

So I guess I am not adding the tmx file in right way to the project.
http://hemelix.com/bug.png

If I try the tmx file in the sample project of cocos2d-x-2.2.5 then looks fine. But if I create a cpp project in cocos2d-x-3.3 then I get a crash (probably my project creation is not OK) or there is some problem in cocos2d-x-3.3

I created my project by the following command
cocos new MyGame -p com.MyCompany.MyGame cpp -d ~/MyCompany

The project its well created.

You must verify that you don’t have more than one pattern for each layer and you have to put the .tmx file and pngs in the Resources folder of the project (mygame/resources).

Sorry, it did not work for me. It looks if I create a simple tmx file by Tiled it crashes in the same point.
Can anybody point what I am doing wrong? It looks my tile map creation is wrong, since some tmx file provided by example work.

Uh! after some trial and error, I noticed the following reason was the root cause. If selected tile (png file) is in different directory than where tmx file is saved, Tiled SW add relative path in the XML file. The relative path goes to the resource and this causes the problem. In my case XML file contained the following:

When drawing map then png file should be in the same folder or later XML file can be edited by removing the relative path.