Jump to content

Cannot change Tilemap's Tileset, even for current tileset


Skeptron
 Share

Recommended Posts

Hi all!

 

I'm facing a weird issue right now. I want to make a game where the mood could suddenly change and for that, I'd like to swap the art of the tilesets. So current map has one layer, with one tileset, and on user action the tileset might change to another (real-time). The topography of the map doesn't change : just the art.

 

The technique I use for this purpose is to use tileset.setImage("myTileset").

 

However, when I do that I get exceptions : 

Phaser.Tileset - image tile area is not an even multiple of tile sizephaser.js:93537 Phaser.Tileset - actual and expected number of tile rows and columns differ

But that happens even if I try to swap current tileset with itself! (which obviously has the correct dimensions, as it's correctly displayed right now!)

 

The code : 

  create(){    this.map = this.game.add.tilemap("map-json");    this.map.addTilesetImage("tileset1", "tileset1-img");    this.map.createLayer("layer");    // Space key to change tileset    this.spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);    this.spaceKey.onDown.add(this.changeTileSet, this);  }  changeTileSet(){    console.log("Changing tileset");    this.map.tilesets[0].setImage(this.game.cache.getImage("tileset1-img", true));  }

Sorry guys, I wanted to do a sandbox but I couldn't find any way of uploading the JSON atlas without having cross-domain issues. If anyone has a solution for that too, I'd be happy!

 

 

Link to comment
Share on other sites

you need to set 

layer.dirty=true

http://phaser.io/sandbox/SCFTwUbL/play

 

you can also use map.addTilesetImage again as an alternative to setImage

// map.tilesets[0].setImage(this.game.cache.getImage("tileset2-img"));map.addTilesetImage('tileset1', 'tileset2-img')    layer.dirty = true;

found here http://www.html5gamedevs.com/topic/5212-breakable-tiles-in-phaser-2/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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