beeglebug Posted August 6, 2014 Share Posted August 6, 2014 I have a json Tiled map loaded, and at a certain point I want to throw that map away and load in a different one (I have the second tilemap loaded already). I'm unsure of the right way to get rid of the current map and load in a new one, particularly when it comes to the display list. I can call the same set of functions I did when adding the original map (game.add.tilemap etc), but this will just add the second map on top of all the sprites. What I need is a way to remove the existing map, and load the new one into the same point in the display list. Is there a simple way of doing this? It seems like phaser avoids exposing the underlying pixi display list too much, so I can't see any obvious functions for interacting with it. Link to comment Share on other sites More sharing options...
beeglebug Posted August 6, 2014 Author Share Posted August 6, 2014 Just a though, should I be using groups for this? I.e add a group called `map`, to which I can remove the current map, and add the new one, without the overall position in the display list changing? My past experience has been more with pixi than Phaser, so im used to manipulating the display list and using displayObjectContainers to set up an initial scene hierarchy. THe fact that phaser automatically adds things to the display list in the order you create them is really throwing me. Are there any examples of display list manipulation floating around, or am i barking up the wrong tree entirely and there is a much easier way to do what I want? Link to comment Share on other sites More sharing options...
Heppell08 Posted August 6, 2014 Share Posted August 6, 2014 In one of my games I just destroy the layer and then recreate the next map on the layer after destroying the previous maps layer. I also have a load of number variables keeping track of what map loads at what time.I did it that way to prevent having many many different state files per level. Also is useful because all the basic game core logic and level changing code is kept in a single state and file.Hopefully that makes some sense but if not I can show you some examples or even the raw function itself. Link to comment Share on other sites More sharing options...
WombatTurkey Posted November 23, 2016 Share Posted November 23, 2016 map_collisions = game.add.group(); map_layers = game.add.group(); map = game.add.tilemap('desert'); map.addTilesetImage('area01_level_tilesnew', 'tiles'); layer = map.createLayer('background', null, null, map_layers); map.createLayer('foreground', null, null, map_layers); layer.resizeWorld(); When you add any new entities from tiled to map_collisions then want to destroy everything: map_collisions.destroy() and map_layers.destroy() and map.destroy() Boom, clean sweep of a tilemap. Wrap the code under game.add.group inside a function LoadLevel(name) or whatever. Link to comment Share on other sites More sharing options...
Recommended Posts