Creating tiles/layers explicitly in script
by Chris Jorgensen · in Torque Game Builder · 09/07/2006 (7:35 pm) · 6 replies
I'm working on a little space game. I've got a level where there are a bunch of nebula as background objects. Presently, I handle this by creating a sprite for each nebula. I have read, however, that tiles speed up performance by a large factor. The nebulas are all of different size/shape. How would I go about converting them to tile layers?
About the author
Owner of Cascadia Games LLC
#2
09/07/2006 (8:04 pm)
You have a couple of options. You could just create the tile layers in TGB and load them up in script. If your nebulas are made from multiple image maps, this is probably the easiest way. If each nebula is just a single image, you could easily do it from script as follows:$nebulaMap = new t2dTileMap() { scenegraph = t2dScene; };
$nebulaLayer = $nebulaMap.createTileLayer ( "1 1 256 256");
$nebulaLayer .setPosition ( "0 0");
$nebulaLayer .setLayer (30);
$nebulaLayer .setStaticTile("0 0", nebulaImageMap);You'd obviously want to change the "256 256" to the actual dimensions of the nebula imagemap, and replace "nebulaImageMap" with the name of the datablock that you're using to point at the nebula graphic.
#3
09/07/2006 (9:30 pm)
^Thanks! I'll try it out soon and let you guys know if I see any benefit or not.
#4
09/09/2006 (8:08 am)
I tried this code alone and with some additional tweaks but couldn't seem to get my tile to be visible. Is there some trick to this in 1.1.1 that I'm missing?
#5
09/09/2006 (8:14 am)
Well, that's pretty much pulled from my current project where it all works fine. My initial thoughts would be to doublecheck the scenegraph name is correct.
#6
Ya, I didn't ge script errors or anything. The tile just didn't appear. I'll give it another shot when I get the chance and see if I can't figure out what went wrong.
@Paul
Well, I sure hope I can get some speedup. But I can see what you're saying. I'll have to try it and report back. :)
09/11/2006 (10:06 pm)
@PhilipYa, I didn't ge script errors or anything. The tile just didn't appear. I'll give it another shot when I get the chance and see if I can't figure out what went wrong.
@Paul
Well, I sure hope I can get some speedup. But I can see what you're saying. I'll have to try it and report back. :)
Torque Owner Paul /*Wedge*/ DElia