TGB game structure
by C Martin · in General Discussion · 10/03/2008 (11:39 pm) · 6 replies
I was just wondering how most people go about setting up their games in TGB. For instance, if you have a series of levels that need to be played out one after the other, is there a higher level structure that governs this?
The problem i'm having is that while most of my objects are event based (reacting on user input or update timers) - there is some processing that I need to do that goes on per frame regardless of interactions. Where would this be normally setup?
I know there is a onUpdateScene method available, but wouldn't that scenegraph be destroyed each time a new level is loaded, or can a scenegraph contain other scenegraphs?
Thanks for your help. :)
The problem i'm having is that while most of my objects are event based (reacting on user input or update timers) - there is some processing that I need to do that goes on per frame regardless of interactions. Where would this be normally setup?
I know there is a onUpdateScene method available, but wouldn't that scenegraph be destroyed each time a new level is loaded, or can a scenegraph contain other scenegraphs?
Thanks for your help. :)
About the author
#2
Your reply indicates that there is one scenegraph that is responsible for all of the objects that are loaded when a level is loaded. Looking at the level files themselves, they appear to create a scenegraph whenever they are loaded. Or is this only done once, when the first level is loaded?
I'm refering to the first line in a level file - which looks like this:
%levelContent = new t2dSceneGraph()
Thanks again! :)
10/04/2008 (1:17 am)
Thanks for the reply!Your reply indicates that there is one scenegraph that is responsible for all of the objects that are loaded when a level is loaded. Looking at the level files themselves, they appear to create a scenegraph whenever they are loaded. Or is this only done once, when the first level is loaded?
I'm refering to the first line in a level file - which looks like this:
%levelContent = new t2dSceneGraph()
Thanks again! :)
#3
10/04/2008 (1:28 am)
Oops, looks like the sceneGraph actually is deleted when you endLevel and recreated when you loadLevel, interesting. In any case, your callback should continue to work.
#4
What i'm planning to do is to specify a class name for the scenegraph that will be consistant between levels and make sure i'm saving any state information that has to persist in global variables - I think that will be fine. :)
Thanks for the help, that has helped me a lot.
10/04/2008 (1:34 am)
I guess that during the time the sceneGraph is unloading and the new sceneGraph is being created it may stop running as expected.What i'm planning to do is to specify a class name for the scenegraph that will be consistant between levels and make sure i'm saving any state information that has to persist in global variables - I think that will be fine. :)
Thanks for the help, that has helped me a lot.
#5
In any case I know this works, just call it once to get it going.
10/04/2008 (1:54 am)
How about a simple self repeating schedule? Or maybe a sceneObject timer, just don't add the sceneObject to a sceneGraph, i'm guessing its timer still gets called.In any case I know this works, just call it once to get it going.
function updateLoop()
{
// do stuff.
schedule( 32, 0, updateLoop );
}
Associate James Ford
Sickhead Games
Not really, its up to you to decide when/how you want to change levels via script.
The sceneGraph itself is not destroyed, just the objects in it. But even if it was, it would STILL work, here's why. You would most likely put this callback in the t2dSceneGraph namespace, eg,
function t2dSceneGraph::onUpdateScene(%this)
{}
Which means it is not tied to a specific sceneGraph, this script is called onUpdateScene for any t2dSceneGraph. However you can put a callback in the namespace of a particular object, but that wouldn't make a lot of sense for a sceneGraph, since they are usually created internally by the sceneWindow and don't have a name.