Array of tiles on a layer?
by Scott Coursey · in Torque Game Builder · 11/08/2005 (7:18 am) · 3 replies
Does anyone know of a decent way to access an array or list of references to all the tiles on a layer?
I want to scan through a layer and check the status of each object.
Thanks.
I want to scan through a layer and check the status of each object.
Thanks.
#2
That is an example of how to observe the type of tile for any given tile count. When you use $layer.pickTile(sceneWindow2D.getMousePosition()); You are given the tile the mouse is currently on. The order of the data is col SPC row in the tile map. Example if the pickTile call returns "5 0" that means from "0 0" you are 5 units right and 0 units down.
@Tom, pickTile as you see works off a set of world cordinates. When you pick a tile you pass it world cords and it returns what tile is there, if any. What you have is bascially saying, go through the tiles and pick a tile ( %thisTile ) and asking it to return what tile %thisTile it is. You already know what tile you are at, and in your example it would be %x SPC %y.
11/08/2005 (11:01 am)
$Layer = $Map.getTileLayer(0);
for(%col = 0; %col < getWord($Layer.getTileCount(), 0); %col++) {
for(%row = 0; %row < getWord($Layer.getTileCount(), 1); %row++) {
%type = $Layer.getTileType(%col SPC %row);
// %type is the type of tile EXAMPE: static tileMapImageMap 1
// The example would mean that at tile %col SPC %row is the
// image tileMapImageMap frame 1 and it is static
}
}That is an example of how to observe the type of tile for any given tile count. When you use $layer.pickTile(sceneWindow2D.getMousePosition()); You are given the tile the mouse is currently on. The order of the data is col SPC row in the tile map. Example if the pickTile call returns "5 0" that means from "0 0" you are 5 units right and 0 units down.
@Tom, pickTile as you see works off a set of world cordinates. When you pick a tile you pass it world cords and it returns what tile is there, if any. What you have is bascially saying, go through the tiles and pick a tile ( %thisTile ) and asking it to return what tile %thisTile it is. You already know what tile you are at, and in your example it would be %x SPC %y.
#3
11/08/2005 (11:16 am)
*hangs head* Forget that it uses world co-ordinates! Thanks for pointing that out.
Torque 3D Owner Tom Perry
//%layer is the handle for the tile layer //%xLimit is the number of tiles along the X axis-1 //%yLimit is the number of tiles along the Y axis-1 for (%x = 1; %x<%xLimit; %x++) { for (%y = 1; %y<%yLimit; %y++) { %tile = %layer.pickTile(%x,%y); //what ever functions or checks you need to do here } }This will go through the first column and then make its way along the X axis.