Quantcast
Channel: Cocos中文社区 - 最新帖子
Viewing all articles
Browse latest Browse all 494966

Load TMX from server?

$
0
0

@eydamson
You can implement it by create a cc.TiledMapAsset object with your tmx file data. But there is a limitation: the image & tsx files used by the tmx file should be in the assets of your project. The logic will be look like this:

// loadFileFromServer should be replaced by actual method which can load file data from server.
var mapNode = this.node;
loadFileFromServer(TMX_URL, function (err, data) {
    var tmxAsset = new cc.TiledMapAsset();
    tmxAsset.tmxXmlStr = data;

    // RELATIVE_PATH_OF_IMAGES is a relative path to the assets folder.
    tmxAsset.tmxFolderPath = RELATIVE_PATH_OF_IMAGES;

    // IMAGE_NAMES is a array which contains all the image files name used by tmx.
    var imgPaths = IMAGE_NAMES.map(function(imgName) {
        return RELATIVE_PATH_OF_IMAGES + '/' + imgName;
    });
    cc.loader.load(imgPaths, function() {
        var map = mapNode.addComponent(cc.TiledMap);
        map.tmxAsset = tmxAsset;
    });
});

Hope it's helpful!


Viewing all articles
Browse latest Browse all 494966

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>