mk12001 Posted August 25, 2015 Share Posted August 25, 2015 Hi guys, I would like to have my tile map randomly created from a selection of 3 tiles. From the examples, I can only see tilemaps preloaded from csv or json, so I'd like to know if this is possible. Thanks. Link to comment Share on other sites More sharing options...
CodeToWin Posted August 25, 2015 Share Posted August 25, 2015 i think it's possible, but it's probably not easy. The most brute force way I can think of is to edit the JSON file within your program. This means parsing the JSON file and replacing the tile entries with a random number that corresponds to one of your desired tiles. This is probably not optimal for anything other than small maps. Best advice is to take a look at the Phaser source and see how these methods actually work, and then modify them as you need. Link to comment Share on other sites More sharing options...
jdnichollsc Posted August 25, 2015 Share Posted August 25, 2015 you can load tilemaps from variables, see my example: var nivelsLayers = [ { "Cam" : { "height":80, "layers":[ { "data":[ ........ ] }}, //More levels]var playState = { preload: function () { //Create your random this.game.load.image('tile', "assets/nivels/n" + actualNivel + "-tile.png"); this.game.load.tilemap('carreteraTileMap', null, nivelsLayers[actualNivel - 1]["Cam"], Phaser.Tilemap.TILED_JSON); }, create: function(){ this.carreteraMap = this.game.add.tilemap('carreteraTileMap'); this.carreteraMap.addTilesetImage('tile'); }} CodeToWin 1 Link to comment Share on other sites More sharing options...
drhayes Posted August 25, 2015 Share Posted August 25, 2015 At heart, a tile map layer is an array of numbers. Replacing those numbers with other numbers should work just fine. You could build a default, empty level, clone it, then modify its data property as much as you want. Link to comment Share on other sites More sharing options...
Recommended Posts