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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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