Jump to content

Automatic load of tilemap images


kay
 Share

Recommended Posts

I'm using the tilemap feature to load levels. But the examples mention, that I have to load all tileset images "manually".

 

So my idea was to load all my stuff and then check the tilemaps in the cache for needed images and load them after the load-complete.

 

This doesn't work. Later in the game, the cache says it doesn't know the keys, where I stored the images at.

 

Is there a better way or do I have to load the json with my own ajax request and get the infos for the loader before I tell it which assets he has to load?

Link to comment
Share on other sites

Yes.

My function looks like this:

  load-tilemap:(id, url)!->    @game.load.tilemap id, url, void, Phaser.Tilemap.TILED_JSON    @game.load.on-load-complete.add-once !~>      map-config = @game.cache.get-tilemap-data id      tilesets = map-config.data.tilesets      for tileset in tilesets        @game.load.image tileset.name, "assets/#{tileset.image}"
  1. loading a tilemap
  2. getting the JSON tilemap data
  3. getting the tileset data
  4. loading all the tilesets configured in the tilemap JSON

Later I use the same JSON tilemap data again to add all the needed tilesets to the created tilemap. But the cache can't find them with the given keys

  create-tileset-images:(tilesets)!->    for tileset in tilesets      @tilemap.add-tileset-image tileset.name, tileset.name
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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