colinvella / phaser-tilemap-plus

Tilemap animations, physics, events and custom property enhancements for Tiled JSON map files
MIT License
72 stars 5 forks source link

Loading tilemap with preloaded json object not working #9

Open matthias-herbst opened 6 years ago

matthias-herbst commented 6 years ago

Passing a preloaded json object to the game.load.tilemap()-function breaks map.

URL parameter is required. Phaser tilemap accepts json object instead of a url.

Is there any workaround?

matthias-herbst commented 6 years ago

Found a solution on my own. I think this would be a great addition to your plugin.

Extend functionality of the Loader.tilemap function (L. 526ff:)

Phaser.Loader.prototype.tilemap = function (t, e, i, a) {
      r.call(this, t, e, i, a);
      // if url == null && json data passed to load tilemap function
      if(e == null && i != null) {
        var cacheKey = n(t);
        this.game.cache.addJSON(cacheKey, null, this.game.cache.getTilemapData(t).data);
      }
      else { this.json(n(t), e); }
 };