Tilemap:Choose Random Tile?


(VanderJamesHum) #1

Im loading level files as usual from OGMO 1, but with the tileset i would like to have a random tile chosen for each tile there is in the level. I have a graphic with squares of different colors which are my tiles, but it is a pain to individually draw each one.

It would be ideal to just paint in ogmo with one tile and when they are placed in the game, wherever there is a tile, a random block from the set will be chosen. Does anyone have any suggestions?

here is what i have and need to change

for each (o in xml.tileLayer[0].tile) {
				
 tileset.setTile(o.@x / Global.grid, o.@y / Global.grid,
 (4 * (o.@ty/Global.grid)) + (o.@tx/Global.grid));
}

(David Williams) #2

Just substitute the id with a random number. You can use FP.rand() or Math.random().

    for each (o in xml.tileLayer[0].tile) {

 tileset.setTile(o.@x / Global.grid, o.@y / Global.grid,
 (FP.rand(endTileID)+beginTileID));
}