Callback when player enters TileMap Tile
by Deozaan · in Torque Game Builder · 12/10/2009 (3:29 am) · 5 replies
Hello,
I've got a large Tilemap with collisions working just fine, and next I would like to have something special happen when the player enters a specific tile. I'm just wondering if there's something built into TileMaps that would allow this.
There is TileScript but I have no idea what this is or how it works.
Would it be easiest to just put a Trigger or invisible SceneObject there and check for collisions or is there something really obvious that I'm missing?
Thanks in advance for your help.
I've got a large Tilemap with collisions working just fine, and next I would like to have something special happen when the player enters a specific tile. I'm just wondering if there's something built into TileMaps that would allow this.
There is TileScript but I have no idea what this is or how it works.
Would it be easiest to just put a Trigger or invisible SceneObject there and check for collisions or is there something really obvious that I'm missing?
Thanks in advance for your help.
#2
Is there anything that does the opposite? You give it a tile and it returns world coordinates?
I need to know the world coordinates of a specific (but randomly chosen each time) tile so that I know where to place the trigger.
Thanks.
12/31/2009 (10:17 pm)
If I recall correctly, pickTile uses world coordinates and returns tilemap coordinates.Is there anything that does the opposite? You give it a tile and it returns world coordinates?
I need to know the world coordinates of a specific (but randomly chosen each time) tile so that I know where to place the trigger.
Thanks.
#3
01/01/2010 (12:18 am)
taken from astardemo code...//GET WORLD POSITION FROM TILE CO-ORDINATES
function getTileWorldPosition(%tileXPosition, %tileYPosition) {
// determine if we were passed a word-list or x/y coords
%tileLayer = tilemap1; //YOUR TILEMAP NAME
if(getWordCount(%tileXPosition) > 1)
{
%tilex = getWord(%tileXPosition, 0);
%tiley = getWord(%tileXPosition, 1);
}
else
{
%tilex = %tileXPosition;
%tiley = %tileYPosition;
}
// %buff just stores stuff real quick -- I like 'getSize' over 'getSizeX', personal preference
%buff = %tileLayer.getTileSize();
%tsx = getWord(%buff, 0);
%tsy = getWord(%buff, 1);
%buff = %tileLayer.getTileCount();
%tcx = getWord(%buff, 0);
%tcy = getWord(%buff, 1);
%p = %tileLayer.getPosition();
%px = getWord(%p, 0);
%py = getWord(%p, 1);
// get the top-left
%tlx = -(((%tcx * %tsx) / 2) + (%tsx / 2));
%tly = -(((%tcy * %tsy) / 2) + (%tsy / 2));
// determine tile world position
%wx = %px + (%tlx + (%tsx * (%tilex++)));
%wy = %py + (%tly + (%tsy * (%tiley++)));
return %wx SPC %wy;
}
#4
01/01/2010 (2:05 am)
Thank you very much.
#5
01/01/2010 (1:56 pm)
no problem
Associate William Lee Sims
Machine Code Games