TileMap
by Richard Baker Jr · in Torque Game Builder · 12/18/2012 (1:24 pm) · 5 replies
I am curious if there is a way in the mouse callback of a tile map to see what the actual (X, Y) cords of the tile you click are.
I gave the tilemap a name, TileMap, enabled mouse callback, then created this function.
function TileMap::onMouseUp(%this, %modifier, %worldLocation, %clicks)
{
}
Now of course I would have the function code do something useful. I am stuck trying to figure out how to get the X, Y of the tile I happened to click. I tried to find a pattern from %worldLocation, which I know is the location of the click in the scene, but I am at a loss of finding out the exact X and Y of the tile I happened to click on.
Any help would be awesome!
--Rick
I gave the tilemap a name, TileMap, enabled mouse callback, then created this function.
function TileMap::onMouseUp(%this, %modifier, %worldLocation, %clicks)
{
}
Now of course I would have the function code do something useful. I am stuck trying to figure out how to get the X, Y of the tile I happened to click. I tried to find a pattern from %worldLocation, which I know is the location of the click in the scene, but I am at a loss of finding out the exact X and Y of the tile I happened to click on.
Any help would be awesome!
--Rick
About the author
I have recently obtained a lot of free time now that my kids are growing older. Baker's Game Studio is now fully operational with no conditions on compile time(occasional runtime) errors. Accepted by Microsoft BizSpark. Time to get serious.
#2
What also never came to mind was finding what pickTile did. I went through the reference and tried all sorts of items off of the t2dTileLayer functions, for some reason when I saw the definition for pickTile I thought of the standard X, Y of the tilemap not the world position.
Again, Thank you so much.
12/18/2012 (1:34 pm)
Going to check that out, thank you very much. I think I fail at searching, the past hour or so I have searched here, google, bing, yahoo, etc... I could not even come close to finding that post. Must have used the wrong params. What also never came to mind was finding what pickTile did. I went through the reference and tried all sorts of items off of the t2dTileLayer functions, for some reason when I saw the definition for pickTile I thought of the standard X, Y of the tilemap not the world position.
Again, Thank you so much.
#3
TileLayer.pickTile(%worldCoords) should return "tileX tileY" of the logical tile (i.e. %worldCoords "100.5 45.123" might return "7 2" meaning 7th tile on 2nd row).
12/18/2012 (2:22 pm)
You can't name a script object the same as its engine-side class name. You should probably rename that to LevelMap or something. The TileMap::XXX() methods should work as is, though, for any tile map object - since that scopes the functions to the actual engine class.TileLayer.pickTile(%worldCoords) should return "tileX tileY" of the logical tile (i.e. %worldCoords "100.5 45.123" might return "7 2" meaning 7th tile on 2nd row).
#4
Yea, the pickTile(%worldCoords) is exactly what I was looking for. As soon as I saw that link it clicked right in my head.
12/18/2012 (2:32 pm)
You know what is funny, classic mistake of typing what I was thinking. The actual name of my tilemap is TileBoard, for some reason I typed what I was thinking about "tilemap".Yea, the pickTile(%worldCoords) is exactly what I was looking for. As soon as I saw that link it clicked right in my head.
#5
12/18/2012 (8:27 pm)
Great to know. I'm going to start using some tilemap art instead of super lame one pixel white blocks stretched to whatever size I need and blended to black.
Torque Owner Doc308
Basically uses the pickTile command along with getWord, etc..