tileMaps in script
by Kevin James · in Torque Game Builder · 07/20/2010 (6:37 pm) · 9 replies
I plan to use something like tileMaps in my next game. I can see the benefit of tilemaps in the designer with all of the great editing features, but what if I want to make tilemaps in script? Is it still worth using the tilemap class or should I populate the scene with tiles using my own custom class?
About the author
Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/
#2
Btw, why do you bother to create it in the editor first?
07/20/2010 (7:04 pm)
Ahh, I see. It would be foolish of me not to use the tilemap functionality. Thanks Patrick!Btw, why do you bother to create it in the editor first?
#3
07/20/2010 (7:32 pm)
Honestly, only because I find it easier to drag it in there and set it up using the rather than do the math for tile sizes vs number of tiles, etc.
#4
07/20/2010 (7:44 pm)
Do individual tiles give you the same functionality as a static sprite?
#5
Collisions may be a bit different but I honestly haven't dug too deeply into that.
Mostly I use the following:
Assign a static sprite to a tile (setStaticTile)
Set an animated sprite (setAnimatedTile) to a tile
Get a tile's x/y from a world position (pickTile)
Clear the tile's contents (clearTile)
Set custom data (setTileCustomData).
All described in detail here.
07/20/2010 (8:13 pm)
Hmmm... Pretty much but you wouldn't try to say setMouseEnabled on a tile but rather set it on the tile layer, then use pickTile on the callback to find out what tile was clicked.Collisions may be a bit different but I honestly haven't dug too deeply into that.
Mostly I use the following:
Assign a static sprite to a tile (setStaticTile)
Set an animated sprite (setAnimatedTile) to a tile
Get a tile's x/y from a world position (pickTile)
Clear the tile's contents (clearTile)
Set custom data (setTileCustomData).
All described in detail here.
#6
07/27/2010 (10:10 pm)
How do I get a tile's world position based on its x/y coordinate?
#7
Note: untested, off the top of my head.
07/28/2010 (12:46 am)
Surprisingly, there's nothing built in for that. I'd use something like this:function tileLayer::getTilePosition(%this, %x, %y)
{
%xOffSet = (%this.getTileCountX() / %this.getTileSizeX() * %x) + (%this.getTileSizeX() / 2);
%yOffSet = (%this.getTileCountY() / %this.getTileSizeY() * %y) + (%this.getTileSizeY() / 2);
%pos = (%this.getPositionX() - %this.getTileSizeX() / 2) + %xOffSet SPC (%this.getPositionY() - %this.getTileSizeY()/ 2) + %yOffSet;
return %pos;
}Note: untested, off the top of my head.
#8
www.torquepowered.com/community/forums/viewthread/57875
sometimes the positions go off the grid, but not too far.
Patrick, I tested your code, but alas the results are way off.
07/28/2010 (1:50 am)
I found this which works well enough:www.torquepowered.com/community/forums/viewthread/57875
sometimes the positions go off the grid, but not too far.
Patrick, I tested your code, but alas the results are way off.
#9
Glad you found something.
07/28/2010 (2:48 am)
Does the same thing, I had a typo in mine where I was getting the tilemap width instead of tile width.Glad you found something.
Torque Owner RollerJesus
Dream. Build. Repeat.
I've become quite fond of using tilemaps. I generally only create it in the editor, name (or class it) and do all the manipulation in script.
Check this thread out as an example of what can be done pretty easily.