Game Development Community

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?

#1
09/07/2006 (7:50 pm)
You wouldn't. I don't think you're going to get much benefit from using a tile layer in this case, and it would be tons of trouble to make variable sized nebulae look right in one. Unless you put each image in it's own tile layer, which I can't imagine that's going to give much a benefit. Tile layers are generally there for using lots of repeating tiling static sized images.
#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
09/11/2006 (10:06 pm)
@Philip

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. :)