Jump to content

switch assets in preload on scene restart


Recommended Posts


i hope i can explain myself :

im trying to restart a scene with a different map without having to preload all the .json files at once so

in preload i have


let maplevel = $("#id").val;
case 2:
this.load.tilemapTiledJSON('map', "url here");
this.load.tilemapTiledJSON('map', "url here");

which throws no errors anywhere


in create

this.map = this.make.tilemap({key : map});
this.tiles = this.map.addTilesetImage('nameasin Tiled', 'tiles');
this.bottomlayer = this.map.createDynamicLayer(0,this.tiles,0,0);
this.wallslayer = this.map.createDynamiclayer(0,this.tiles,0,0);

when the sprite hits a certain kind of tile (number 12 on bottomlayer) a function calls :


if(mapevent == 0){
shake/fade/delayedcall -> scene.restart // trap, player dies works it restarts the scene with player in the right place

if(mapevent == 12){ //this has to move from maplevel 1 to maplevel2

the first bit is a gameover event so that puts the player at the start of level 1 , which seems to work fine

the second is a next level event , this bit throws no errors , it doesnt give any "key not defined" or anything at all so i assume its loaded. I actually know its loaded since if i load both files with different key names and i use 


statement in the 


section it displays the right one, however if i use it in preload everything fades and restarts but it displays the same layout as level 1

from all i can dig up i could as well load the assets in scene 1 (this is scene 9) and they would be available, so i can make it work thats not the issue

my issue is, eyes on the future that i would like to only load what's needed without having to add separate scenes, i already expect to have dozens or maybe like a 100 scenes (whew ...) by the time its anywhere near finished so

memory wise i think it would be advisable to only have the current JSON file loaded and size-wise it would be a lot easier if i could just use a string for the filename on restart, that would save a lot of bytes as i have 9 levels for this one alone, if i have to include <script src tags> for 9 scenes for each separate level the pagesize will increase dramatically

ive been googling for a few hours now and i cant really find exactly what i need and as it throws no errors i have no clue what's wrong. My best guess would be that you can't alter the assets on a scene restart and it sticks with whatever is loaded the first time the scene is started, if that's so then i guess it can't be helped but if there would be a way to do this id be much obliged if someone takes a minutre to explain

I just figure its better to do it that way up front instead of optimizing it all after total creation so in short 

Can i load different files to have different map layouts when i call scene.restart ?


thanks in advance,


Link to comment
Share on other sites


  • Recently Browsing   0 members

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