Jump to content

Manually adding and retrieving tilemap from cache


AlanSmithee
 Share

Recommended Posts

Hello.

 

I am trying to use a tilemap (which is not persisted to any form of database or file) over several states by using the cache.

 

STATE ONE

// Creating the tilemap..var map = this.game.add.tilemap();map.addTilesetImage('ground_1x1');    map.create('level1', 40, 40, 32, 32);map.setLayer(0);// In this state I am editing the map by adding / removing tiles from the layers// I then add it to the cachethis.game.cache.addTilemap('test', map);// Then when changin state, I'm clearing world but keeping cache:this.state.start('LevelTwo', true, false);
STATE TWO
// I am loading the map from the cachethis.game.load.tilemap('test', this.game.cache.getTilemapData('test').url, null, Phaser.Tilemap.CSV);        // And adding it back to the gamethis.game.add.tilemap('test');

But this doean't work..

 

I have tried to use my cached map as both the url and/or data argument when loading it back to the game, but nothing seems to work.
 
It is possible that this is conceptually wrong, and that there is some much easier way to do this then to use the cache like I am trying to - if so please tell me! I do not, however, want to keep world between states since most of the world related information is not shared between states. 
 
I am also wondering how to get the actual map data from a map, since i would like to persist it at a later point.. as i inspect my map, I notice that the data field is empty, is there something that needs to be done to generate this?
 
Thanks in advance! / AS
Link to comment
Share on other sites

  • 8 months later...
 Share

  • Recently Browsing   0 members

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