Create TiledMap from code dynamically in CC3

Hi, I want to make TiledMaps dynamically from code, creating and xml and assigning it through the tmxXmlStr property, similar to using var tileMap = new cc.TMXTiledMap(xml, "res/mytilesets"); in Cocos2d-x JavaScript. I have the TiledMap created in the editor and showed on the screen. After running the following code for changing the data encoding:

var xml = '<?xml version="1.0" encoding="UTF-8"?><map version="1.0" orientation="orthogonal" width="16" height="16" tilewidth="32" tileheight="32"><tileset firstgid="1" name="mytileset" tilewidth="32" tileheight="32"><image source="mytileset.png"/></tileset><layer name="Layer 0" width="4" height="4"><data encoding="csv">1,2,2,1,2,1,1,2,2,1,1,2,1,2,2,1</data></layer></map>';
find('Canvas/TiledMap').getComponent(TiledMap).tmxAsset.tmxXmlStr = xml;
console.info(find('Canvas/TiledMap').getComponent(TiledMap).tmxAsset.tmxXmlStr);

The property has been modified but no changes are shown on screen tilemap.

Any idea?. Thanks.

In cocos creator, the asset loading process is entirely depending on the asset system, so you must import tile map files into the editor, only then you can use it in the code as a Tilemap asset, you don’t need to manipulate the raw data.

Ok, I thought that it could be done at runtime, like in Cocos2d JavaScript.
Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.