Jump to content

How to Access Asset Pack?


Recommended Posts




I'm adding some extra functionality to the Phaser.Tilemap class and I've recently converted my loading code to use the new-ish Asset Pack feature. All of my tilemaps are loaded in sections like so:

{    "maze":  [        {            "type": "tilemap",            "key": "maze",            "url": "assets/tilemaps/maps/Maze.json",            "data":  null,            "format": "TILED_JSON"        },        {            "type": "image",            "key": "creatures_tileset",            "url": "assets/tilemaps/tiles/Creatures.png"        },        {            "type": "image",            "key": "items_tileset",            "url": "assets/tilemaps/tiles/Items.png"        },        {            "type": "image",            "key": "world_tileset",            "url": "assets/tilemaps/tiles/World_Tiles.png"        },        ...

and I thought it'd be great if I could iterate through this manifest and automatically load every tileset into my tilemap, kinda like:

for (var obj in manifest.section)    if (obj.type === "image")        map.addTilesetImage(obj.key);

But I actually can't find a function in Phaser.Cache or Phaser.Loader (or somewhere else?) that lets me access the .json.


If there is no easy solution, I would just load the asset pack as a .json:

this.load.json("manifest", "assets/manifest.json");// ... later ...manifest = game.cache.getJSON("manifest");// Loading code here.

Is that the preferred way of doing it? 

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...