Tile Trigger
by tODD k. · in Torque Game Builder · 06/16/2009 (7:19 pm) · 4 replies
Is there a way to set a trigger on a tile? Basically, I'd like to send a collision callback on a tile but without physics. Since I have walls in the game, so the player needs to send out physics. I have my walls and trigger objects on different tile layers.
#2
AFAIK you can simply define an onCollision method on your tile map object and in the tile map editor select all tiles for which you want to have collisions enabled and check their "Collision" checkbox.
So (without really trying any of this), you should be able to simply set the "Class" property under "Scripting" on your tile map object to something like "MyTileMap" and define an "onCollision" method like so:
To have specific data on each tile for use by the method, simply use the "Custom Data" field in the tile editor. This data can then be retrieved with the "getTileCustomData" method.
06/17/2009 (11:42 am)
Re your original question:AFAIK you can simply define an onCollision method on your tile map object and in the tile map editor select all tiles for which you want to have collisions enabled and check their "Collision" checkbox.
So (without really trying any of this), you should be able to simply set the "Class" property under "Scripting" on your tile map object to something like "MyTileMap" and define an "onCollision" method like so:
function MyTileMap::onCollision( %srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points )
{
// Check collision objects for the ones wanted and act on them ...
}To have specific data on each tile for use by the method, simply use the "Custom Data" field in the tile editor. This data can then be retrieved with the "getTileCustomData" method.
#3
I learned you need to get the x,y of that particular tile using pickTile, and retrieve the custom data using getTileCustomData. And I believe %srcRef & %dstRef are used for tile purposes, Although I'm not sure I'm implementing it correctly. Any ideas?
06/18/2009 (9:17 am)
Very helpful Rene, thank you! This leads me to some more questions (of course!). What I'm trying to achieve is when the player collides with a tile, change that tile to another tilemap. What I have so far:function MyTileMap::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.class $= "playerClass")
{
//get coordinates of tile
%tilecord = %layer.pickTile( getword(%worldPos,0), getword(%worldPos,1) );
//get custom data of tile
%data = %layer.getTileCustomData( getword(%tilecord,0), getword(%tilecord,1) );
//change image map of tile - frame 5 of image tilesImageMap
%dstRef.setImageMap("tilesImageMap", 5);
}
}I learned you need to get the x,y of that particular tile using pickTile, and retrieve the custom data using getTileCustomData. And I believe %srcRef & %dstRef are used for tile purposes, Although I'm not sure I'm implementing it correctly. Any ideas?
#4
setStaticTile(%tileX, %tileY, %imageMap, [%frame]); //or
setStaticTile(%position, %imageMap, [%frame]);
%srcRef and %dstRef refer to the objects that sent and received collisions. Figure out which of those you is the TileLayer and do:
%srcObj.setStaticTile(%tilecord, "tilesImageMap", 5);
Note that you don't need to break apart the %tilecord for most functions that act on t2dTileLayer.
06/18/2009 (10:56 am)
I think what you want is:setStaticTile(%tileX, %tileY, %imageMap, [%frame]); //or
setStaticTile(%position, %imageMap, [%frame]);
%srcRef and %dstRef refer to the objects that sent and received collisions. Figure out which of those you is the TileLayer and do:
%srcObj.setStaticTile(%tilecord, "tilesImageMap", 5);
Note that you don't need to break apart the %tilecord for most functions that act on t2dTileLayer.
Torque Owner tODD k.
tdn.garagegames.com/wiki/Torque_2D/GenreTutorials/RPGTile
and then BAM! it ended, does anyone know of a similar but complete version of that?