Tile Maps
by David Deschenes · in Torque Game Builder · 07/09/2009 (12:08 pm) · 8 replies
Ok i have a problem reguardig finding the absolute center of a specific tile within a tile map. im not really sure if there is a way to do that or if you have to construct your own method, but any assistance would be greatly appreciated. also what exactly do active tiles do?
#2
07/09/2009 (1:50 pm)
ya, im just trying to make sure that objects that i place in the tiles have even spacing.
#3
function getTileCenter(%layer, %tileX, %tileY)
{
//get the world coordinates of the tileLayer
%LayerPosX = %Layer.getPositionX();
%LayerPosY = %Layer.getPositionY();
// get tile width and height
%tilesize = %layer.GetTileSize();
%tilewidth = getWord(%tilesize, 0);
%tileheight = getWord(%tilesize, 1);
// get the upper left X and Y
%width = %layer.GetWidth();
%height = %layer.GetHeight();
%x = %layerPosX - (%width / 2);
%y = %layerPosY - (%height / 2);
// get what half the tile is
%halfx = %tilewidth / 2;
%halfy = %tileheight / 2;
// get the final position
%xcoord = %tilex * %tilewidth + %halfx;
%ycoord = %tiley * %tileheight + %halfy;
%x = %x + %xcoord;
%y = %y + %ycoord;
return %x SPC %y;
}
07/09/2009 (8:32 pm)
Here is some script code to return the world position of the center of a tile.function getTileCenter(%layer, %tileX, %tileY)
{
//get the world coordinates of the tileLayer
%LayerPosX = %Layer.getPositionX();
%LayerPosY = %Layer.getPositionY();
// get tile width and height
%tilesize = %layer.GetTileSize();
%tilewidth = getWord(%tilesize, 0);
%tileheight = getWord(%tilesize, 1);
// get the upper left X and Y
%width = %layer.GetWidth();
%height = %layer.GetHeight();
%x = %layerPosX - (%width / 2);
%y = %layerPosY - (%height / 2);
// get what half the tile is
%halfx = %tilewidth / 2;
%halfy = %tileheight / 2;
// get the final position
%xcoord = %tilex * %tilewidth + %halfx;
%ycoord = %tiley * %tileheight + %halfy;
%x = %x + %xcoord;
%y = %y + %ycoord;
return %x SPC %y;
}
#4
07/10/2009 (12:42 pm)
Thanx a ton! you didnt have to go through the trouble of writing that for me, i was just wondering if there was a built in way of doing it, but it works all the same.
#5
07/10/2009 (12:47 pm)
No worries, I had it already since I need that capability in my game and I don't mind sharing.
#6
07/10/2009 (8:38 pm)
So you are working with tiles too? if you dont mind me asking, do you know if there is a way to return the name of the imagemap that you apply to the tile in the Tilemap editor? i know that you can do it with static sprites but i dont know how with tilemaps.
#7
%tilelayer.setTileCustomData()
You can give a tile a custom data value, which could be the name of the sprite that it represents or some other useful value then retrieve it when you need it.
07/11/2009 (6:59 am)
I didn't see a command for that in the documents but if you use this command -%tilelayer.setTileCustomData()
You can give a tile a custom data value, which could be the name of the sprite that it represents or some other useful value then retrieve it when you need it.
#8
07/11/2009 (3:57 pm)
ya i was lookin at that myself, but i think im gunna go in a different direction. thanks for all the help
Torque Owner Steve D