Jump to content

Trying to change tilemap, textures won't load


Squiro
 Share

Recommended Posts

Hello, I started using Phaser few days ago, so I'm still new to this.

 

I'm making a game with multiple levels. Each level has his own tilemap. What I want to do is the following: when a level ends, the current tilemap is destroyed and the tilemap of the next level is loaded.

 

I tried using this code, but it doesn't work very well because it loads the map (or at least, the blockedLayer of the map), but without any textures on it. It completely ignores the tileset. Obviously I loaded the map and the tileset in the preload function, so this is not the error. Also, both maps use the same tileset.

function changeMap(){    if (currentMap == 1)    {        backgroundLayer.destroy();        blockedLayer.destroy();        arbol.destroy();        nieve.destroy();                map = game.add.tilemap('level1');                map.addTilesetImage('tiles', 'gameTiles');        map.addTilesetImage('aconcagua', 'gameTiles2');        backgroundLayer = map.createLayer('backgroundLayer');        blockedLayer = map.createLayer('blockedLayer');        arbol = map.createLayer('Arbol');        nieve = map.createLayer('Nieve');        map.setCollisionBetween(1, 2000, true, 'blockedLayer');        backgroundLayer.resizeWorld();        create();    }    if (currentMap == 2)    {        backgroundLayer.destroy();        blockedLayer.destroy();        arbol.destroy();        nieve.destroy();        map = game.add.tilemap('level2');                map.addTilesetImage('tiles', 'gameTiles');        map.addTilesetImage('aconcagua', 'gameTiles2');        backgroundLayer = map.createLayer('backgroundLayer');        blockedLayer = map.createLayer('blockedLayer');        arbol = map.createLayer('Arbol');        nieve = map.createLayer('Nieve');        map.setCollisionBetween(1, 2000, true, 'blockedLayer');        backgroundLayer.resizeWorld();        create();    }

How can I fix this? Is there another way to change tilemaps without using States?

 

Thank you in advance.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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