FineRapha

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. I know it's an old thread. But it was the first result on Google for me. So, here's my approach (using tiled maps). First, I create a layer (using Tiled) with all possible locations layer_item_placement = map.createLayer( 'item_placement' ); layer_item_placement.resizeWorld(); layer_item_placement_available = []; for( var i = 0 ; i < layer_item_placement.layer.data.length; i++ ) { for( var j = 0 ; j < layer_item_placement.layer.data[i].length; j++ ) { if(layer_item_placement.layer.data[i][j].index >= 0 ) { layer_item_placement_available.push({ x:layer_item_placement.layer.data[i][j].x * 32, y:layer_item_placement.layer.data[i][j].y * 32 }); } } } Then I create my objects: for( var i = 0 ; i < 50 ; i++ ) { var xy = layer_item_placement_available[ _rand( 0 , layer_item_placement_available.length - 1 ) ]; var object = game.add.sprite( xy.x , xy.y , 'objects' , _rand( 0 , 49 ) ); // 49 == Max sprite number furniture.add( object ); } Got all objects inside the area I wanted.