Game Development Community

Accessing objects using Parallax Layers

by Konrad Carstein · in Torque Game Builder · 07/08/2008 (9:47 pm) · 5 replies

So I haven't bugged anybody in at least a couple of days with questions, so I'm back with another. I think I'm still just trying to get a grip of the fundamentals of TGB and soon a lot will start snapping into place for me.

As per another thread, I've implemented the Parallax Layers in my project to create a simple GUI layer. I seem to be missing though how I reference objects on that layer to make adjustments to them when other things are happening in my main layer.

Simple example. If on my main GUI layer I have a couple images representing the number of lives the player has left. When my player "dies" I want to remove one of those images on the GUI layer.

Could somebody give me a code snippet on how to do this? I don't seem to recall where the new SceneWindow2D (I assume that is what it is) for the GUI is ever given a reference. So I'm just a bit stuck on how I will call it from the rest of my code.

Thanks again!

#1
07/08/2008 (10:16 pm)
In short, you can reference them just like a normal object in the scene.

I imagine that you have setup a H.U.D. using actual scene objects loaded into a new scenewindow/graph (and not a GUI loaded from a .gui file)? When you create these objects, you can either give them a name or store their information away in a SimSet or something similar.
#2
07/08/2008 (10:31 pm)
You are correct. No .gui, just loading a level file into the foreground. For some reason I under the impression that I would have to reference which scene window the object was on.

So basically if dragged an object on to the scene for the level file that I am loading in the HUD, and give it a name like "playerLifeOne", for lack of a better example.

I feel like I should be able to reference by name like %playerLifeOne.safeDelete() or something similar. But the proper syntax escapes me. I realize its not a local reference, but nowhere did I declare it a global one either. So once, again something is escaping me.
#3
07/08/2008 (10:43 pm)
If you give the scene object the name "playerLifeOne", then to reference it you just type:

// Blah
echo (playerLifeOne.getId());
 
// Delete
playerLifeOne.safeDelete();
 
// Misc function
playerLifeOne.myFunction();

When a SimObject (all *objects* are SimObjects) is created it is given a unique ID no matter what type of object it is, or where it is. As long as you have the object's id (or in this case a unique name 'playerLifeOne') then it can be referenced properly.

Names and ID's are unique and global.
#4
07/08/2008 (10:50 pm)
Well I guess that is easier then I expected. So, out of curiosity in some examples and such I've read, I'll see something like this done:

function PlayerClass::onLevelLoaded(%this, %sceneGraph){

     $player = %this;

}

Now this doesn't really seem right to me. This would mean that any object that is of the type "PlayerClass" would run this function when the object gets loaded, basically overwriting the global reference to the $player

From your example above, if I have a single object in the scene that represents the player, I could access it directly by just calling its name. There would be no deed for the global reference to it.

Do I understand that correctly?
#5
07/08/2008 (10:59 pm)
*Nods*

The only real value in doing the above is switching out control of a player, but there are better methods to handle this than in the example.