Is there ANY way to get a callback from a Tile Layer?
by Dennis Harrington · in Torque Game Builder · 06/19/2007 (1:58 pm) · 11 replies
I've tried every possible combination of collision send/response modes between a tile layer and a sprite and I cannot for the life of me get a callback out of a tile layer, either having a tile layer show up in the sprite's callback or the sprite in the tile layer's callback. Is there any way to accomplish this or does an object HAVE to be able to send a collision in order to send a callback?
It just seems odd to me that you can set a tile layer to do a callback but it still doesn't work. Can someone definitively verify for me one way or the other whether it's possible to get a callback from a tile layer?
If this can't be done then I may have to just attach invisible sprites to each tile and use the sprite's collision response but that seems a bit clumsy.
Thanks in advance.
Dennis
It just seems odd to me that you can set a tile layer to do a callback but it still doesn't work. Can someone definitively verify for me one way or the other whether it's possible to get a callback from a tile layer?
If this can't be done then I may have to just attach invisible sprites to each tile and use the sprite's collision response but that seems a bit clumsy.
Thanks in advance.
Dennis
#2
Can someone explain why tile layers aren't allowed to send collisions? Is this due to potential performance issues?
06/19/2007 (4:58 pm)
Yes, all of the relevant tiles in the tile layer have their collision polygons configured and this is in version 1.1.3. And just to clarify, I can get a collision response out of the tiles in the tile layer, such as having a sprite clamp on to it, for example. But in this case, I'm only concerned with getting a callback sent when a collision is taking place.Can someone explain why tile layers aren't allowed to send collisions? Is this due to potential performance issues?
#3
As R2D2 would carry and give to you after you repair him... "GG Community, you're our only hope!"
-Dave C.
21-6 Productions
03/18/2008 (11:30 pm)
I'd love to get some information on this as well. It looks like it has something to do with the 'TileScript' property on a tile - however I am unable to find any information on how to define, setup, or even what exactly these are. Any information at all on getting collisions from tiles would be useful. Various documents mention being able to have a tile damage the player - however without being able to detect collisions on them, it's impossible to call a script to damage the player! As R2D2 would carry and give to you after you repair him... "GG Community, you're our only hope!"
-Dave C.
21-6 Productions
#4
I would double check those settings and doublecheck the name and class of your tilelayer and sprite object, and make sure your onCollision is for the sprite object, not the tile layer. In the onCollision the %dstRef will contain the logical location of the tile.
Greg
03/20/2008 (5:30 pm)
I can verify that it is absolutely possible to have a sprite object with collision callback enabled send the callback when it hits tiles in a layer that has recieve collision enabled. I would double check those settings and doublecheck the name and class of your tilelayer and sprite object, and make sure your onCollision is for the sprite object, not the tile layer. In the onCollision the %dstRef will contain the logical location of the tile.
Greg
#5
When building a tile layer, there is a dropdown labeled "Tile Script".
So if I have a tile layer shaped like a big cavern, and there are 5 tiles in this cavern that are lava tiles, and when you touch those - and only those - tiles, I need to tell the player, "I'm a lava tile. You lose 3 dmg points!"... how would I do that specifically?
My apologies if you answered that above and I was a bit dense to grasp that. =)
03/20/2008 (6:07 pm)
More specifically, my question was about how to get have a script called from an individual tile.When building a tile layer, there is a dropdown labeled "Tile Script".
So if I have a tile layer shaped like a big cavern, and there are 5 tiles in this cavern that are lava tiles, and when you touch those - and only those - tiles, I need to tell the player, "I'm a lava tile. You lose 3 dmg points!"... how would I do that specifically?
My apologies if you answered that above and I was a bit dense to grasp that. =)
#6
It might be easier to store your "5 damage" in the tile's "CustomData" field rather than the Script field. Then you can do something like...
I don't know the specifics of setting up an oncollision callback to work with a tilelayer, but assuming you know the world position the player is at / colliding with, and you know it is a tile, you can use pickTile / getTileCustomData to do the rest...
03/20/2008 (8:28 pm)
I believe Tile scripts are usually used to do something special when that tile first comes onscreen, which triggers this callback, in which you can parse the %script.function t2dTileMap::onTileScript( %this, %layer, %tile, %script )
It might be easier to store your "5 damage" in the tile's "CustomData" field rather than the Script field. Then you can do something like...
function onCollision( ... )
{
%tilecord = %layer.pickTile( getword(%worldPos,0), getword(%worldPos,1) );
%data = %layer.getTileCustomData( getword(%tilecord,0), getword(%tilecord,1) );
if ( getword(%data,0) $= "damage" )
{
%unit.damage( getword( %data,1) );
}
}I don't know the specifics of setting up an oncollision callback to work with a tilelayer, but assuming you know the world position the player is at / colliding with, and you know it is a tile, you can use pickTile / getTileCustomData to do the rest...
#7
03/20/2008 (10:14 pm)
Ah! Okay, that makes perfect sense. I can see how this would work now. However, I see the same problem with the drop-down list that I saw with the Tile Script. With the Tile Editor open, I see there is a drop down list labeled 'Custom Data'. However, my only options in this list are 'None' and 'No Change'. How can I add more options to this list? I would imagine it's getting defined somewhere, only I can't seem to find where...
#8
The list just saves previous things you have typed in for convenience.
03/20/2008 (10:17 pm)
You actually just start typing '-)The list just saves previous things you have typed in for convenience.
#9
03/20/2008 (10:26 pm)
Doh! Okay, got it. Thanks a ton!! =)
#10
Okay. So I've gotten this far, which is pretty cool. My 'end result', so to speak, is to be able to determine when we are and when we are not touching certain tiles. (If there was a 'onCollisionEnded' function, this would be quite a lot easier!). Any suggestions on where to go next?
03/20/2008 (10:58 pm)
Hrm... okay, one more question related to this. Using the above suggested code is great to get the tile that is currently behind the player. Only I want to get the tile that we are touching (or, in this case, the tile that is below the player, being the floor). I'm attempting to use the 'getCollisionList' method each tick on my player to see if we are or if we are not touching the floor (because if we are, then I'm resetting a double jump count). However, when I try and allow the tileLayer to send collisions, it says that this is not allowed ("Send Collision not allowed for this object!"). Okay. So I've gotten this far, which is pretty cool. My 'end result', so to speak, is to be able to determine when we are and when we are not touching certain tiles. (If there was a 'onCollisionEnded' function, this would be quite a lot easier!). Any suggestions on where to go next?
#11
See if you can get a callback to occur doing that for either the player ( with the tilelayer as the hit object ), or the tilelayer ( with the player as the hit object ).
I would reread Tetraweb's post above, sounds like oncollision against tiles DOES work, and the first parameter is the tilecord.
03/21/2008 (12:12 am)
So try setting the tilelayer to receive collisions and your player to send ( or send and receive ). See if you can get a callback to occur doing that for either the player ( with the tilelayer as the hit object ), or the tilelayer ( with the player as the hit object ).
I would reread Tetraweb's post above, sounds like oncollision against tiles DOES work, and the first parameter is the tilecord.
Torque Owner Melissa Niiya
What version of TGB are you using?