Game Development Community

Creating objects in script 2

by Scott Jaworski · in Torque Game Builder · 08/18/2006 (6:16 am) · 2 replies

Copied from another topic that I don't think anyone is checking...

I'm not quite sure I understand the solution here: http://www.garagegames.com/mg/forums/result.thread.php?qt=48954. I'm trying to do something similar; load tiles from a map file dynamically based on user input; not at game load up time. Based on what I see above and in my .t2d file where other things get created, I should be able to do the following in my map.cs file:

$map01 = new t2dStaticSprite() {
	scenegraph = SceneWindow2D.getScenegraph();
	imageMap = "tilesgroundImageMap";
	frame = "1";
	position = "0 0";
	size = "15 13.8";
	layer= "3";
};

I don't get any errors at runtime, but the graphic doesn't show up either. Just for reference, I'm copying information from a tile I inserted with the editor:

new t2dStaticSprite() {
      imageMap = "tilesgroundImageMap"; 
     frame = "1";
      position = "11.5 -16.9"; 
     size = "15 13.8"; 
        mountID = "4";
};

I tried changing the SceneWindow2D to the name of the variable at the top of the t2d file "levelContent" and that didn't work (threw an error), and I've added a mount="5"; (next number in the sequence) but that didn't seem to do anything. I've also tried assigning it a class, but then what do I do on it's onLevelLoaded function? Any help?

#1
08/21/2006 (10:57 am)
I am assuming you left the scenewindow name set to the default of "SceneWindow2D". If thats the case I would guess its the layer you are setting.

I see you are setting your layer to 3. Make sure that is above your background layers, tile maps, etc. if you set the layer below another objects, your sprite will be hidden behind the other object. Try changing the layer to 0 and see if it shows up. Another thing I just noticed. You are setting your frame to 1. Is your static image a cell type with multiple images in 1 file? If it is a single (full) image you should be using frame=0.

You should not need to define the mountID.

Hope that helps.
#2
08/22/2006 (6:54 am)
Thanks for the feedback. Finally in desperation after nothing else worked, I began to think that sceneWindow2D wasn't defined yet, since it was throwing no errors but not doing anything (I was also doubting my sanity). I moved my exec() command to AFTER the loadlevel line in game.cs and viola! My tile done showeth. I have no idea what the actual fix is, but this works for me for the time being, since ultimately, it will be going from a GUI to the loadlevel function based on a file. I would be interested in knowing why it needed to be after the loadlevel call to see the tiles though. All that i had graphics wise on the screen were the TGB background and 2 tiles in different locations that I had loaded through the builder and I changed nothing from the post above.