Game Development Community

SceneView to contain template items

by Jake Davis · in Torque X 2D · 02/16/2011 (1:17 am) · 2 replies

Hello all. I've searched for the past few hours in the forums and have found various posts about creating a SceneView to hold template items and then load it and then loading another Scene that you want to use your template items in. None of the threads that I found were clearly explained how this was accomplished and from my experimentation I have not been able to get it to work. So, i'm not sure if anyone else got it to work or if I'm just not doing it correctly.

Here is a scenerio: I create a Scene in the builder and put my one object such as a player sprite in it. I then create another Scene which is "Level 1". I now want to load my template scene as this will contain my player sprite that I want to use in various levels. Right after that I then load my level that I want this sprite to show up in.

SceneLoader.Load("template.txscene"); // Contains my player sprite that I want to use in multiple levels
SceneLoader.Load("Level1.txscene"); // Level that I want to put my player sprite into

When I load the level, I can't see the sprite that I had in my template scene because I'm assuming that Level1 is now at the top of the SceneGraph. What do I have to do to "inject" my sprite from the template scene into Level1 which is displaying. Will I have to do some work in the code to move it to its start postion and somehow link it to the current Scene that was loaded after the template?

Thanks for any help you can give.

#1
02/16/2011 (5:47 pm)
If you name your template you can create and register a new t2dsceneobject in after your new level is loaded.

ex. if your template is named "template1" in txb after your two sceneload

you would call something like

T2dSceneObject temp = (T2DSceneObject)TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("template1").Clone();
TorqueObjectDatabase.Instance.Register(temp);

but also be aware i think that when you load two scenes you will have two "DefaultSceneGraph" unless you change the name, also you would have to make sure your camera is set up correctly.

Atleast thats what troubled me, and still is somewhat finicky. My code uses pretty much the same concept as you.
Good luck, hope this helps
#2
02/16/2011 (6:18 pm)
Thanks for the help Raymond, I believe that one of your posts is the one that I found on this topic. I thought that I would have to use a template object and clone it...I also saw the problem with the two scenegraphs. Thanks again.