Skeptron Posted October 28, 2015 Share Posted October 28, 2015 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 differBut 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 More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 Hey Skeptron! If you put game.load.crossOrigin = 'anonymous'; in your preloader() method, you should be able to run it in a sandbox/jsFiddle. Here's an example where a TileMap loading an external JSON file is used.http://jsfiddle.net/chongdashu/vr96a9yh/ Skeptron 1 Link to comment Share on other sites More sharing options...
Skeptron Posted October 29, 2015 Author Share Posted October 29, 2015 Hmmm I'm pretty sure I tried that but it didn't work. It's probably related to the hosting server. I see you put your files on GitHub : maybe I should do that as well. Link to comment Share on other sites More sharing options...
jmp909 Posted October 29, 2015 Share Posted October 29, 2015 you need to set layer.dirty=truehttp://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/ chongdashu 1 Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 Hmmm I'm pretty sure I tried that but it didn't work. It's probably related to the hosting server. I see you put your files on GitHub : maybe I should do that as well.Yeah, that or imgur Also, disclaimer that that isn't my code/resources. It was another forum user. Link to comment Share on other sites More sharing options...
Skeptron Posted October 29, 2015 Author Share Posted October 29, 2015 (just for me : updated example with back and forth tileset change : http://phaser.io/sandbox/szpizADP/play ) Link to comment Share on other sites More sharing options...
Recommended Posts