Newbie question about scenegraphs
by Alex Prose · in Torque Game Builder · 07/09/2009 (6:47 pm) · 6 replies
I'm having a lot of problems figuring out how to add objects to the existing scene graph.
For instance, here's my problem:
I modify the game.cs files in the gamescripts folder to contain
---------
exec("./createDummy.cs");
createDummy();
--------
createDummy.cs contains the function:
-------
function createDummy.cs ()
{
$dummyObj::object = new t2dSceneObject() { scenegraph = %scenegraph; };
}
--------
Now this seems to add it to the scene, but whenever I try to access the object it gies me in-game debug error of:
"Object '1478' is not in a SceneGraph!"
If I create a new scenegraph within the function, it, of course, gives me a similar message saying:
"Object '1478' is in a different SceneGraph!"
I get this same problem for any objects I try to dynamically create. They don't show up because they aren't in a SceneGraph, or the scenegraph.
One solution I found was using "%this.getSceneGraph()", but thaty only worked in another script when I was calling "sceneWindow2D::onMouseDown()"
For reference, I'm using v1.7.4
Any suggestions? I think I jsut don't understand how the system works.
For instance, here's my problem:
I modify the game.cs files in the gamescripts folder to contain
---------
exec("./createDummy.cs");
createDummy();
--------
createDummy.cs contains the function:
-------
function createDummy.cs ()
{
$dummyObj::object = new t2dSceneObject() { scenegraph = %scenegraph; };
}
--------
Now this seems to add it to the scene, but whenever I try to access the object it gies me in-game debug error of:
"Object '1478' is not in a SceneGraph!"
If I create a new scenegraph within the function, it, of course, gives me a similar message saying:
"Object '1478' is in a different SceneGraph!"
I get this same problem for any objects I try to dynamically create. They don't show up because they aren't in a SceneGraph, or the scenegraph.
One solution I found was using "%this.getSceneGraph()", but thaty only worked in another script when I was calling "sceneWindow2D::onMouseDown()"
For reference, I'm using v1.7.4
Any suggestions? I think I jsut don't understand how the system works.
#2
--------
function createDummy()
{
$dummyObj::object = new t2dSceneObject();
$dummyObj::object.addToScene(testgraph);
}
--------
I still have the same problem. Is there some special function or variable selector I'm supposed to use to access the scenegraph "testgraph"?
07/09/2009 (9:13 pm)
I named the scenegraph "testgraph" and tried:--------
function createDummy()
{
$dummyObj::object = new t2dSceneObject();
$dummyObj::object.addToScene(testgraph);
}
--------
I still have the same problem. Is there some special function or variable selector I'm supposed to use to access the scenegraph "testgraph"?
#3
07/09/2009 (10:32 pm)
If you have a scenegraph named "testgraph" then you should just be able to specify the scenegraph for the object:function createDummy()
{
$dummyObj::object = new t2dSceneObject()
{
SceneGraph = testGraph;
};
}The alternative is to edit your startGame method to look like this:function startGame(%level)
{
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
// Set the Default Scenegraph.
// Note: Any scene object created without a scenegraph specified will be
// automagically added to this scenegraph!
t2dBeginScene( sceneWindow2D.getSceneGraph() );
}
#4
<code>
$DummyObject = new t2dSceneObject() { SceneGraph = SceneWindow2D.GetSceneGraph() } ;
</code>
...so it'll figure out the scene graph for you.
07/10/2009 (7:49 pm)
You can always do something like<code>
$DummyObject = new t2dSceneObject() { SceneGraph = SceneWindow2D.GetSceneGraph() } ;
</code>
...so it'll figure out the scene graph for you.
#5
07/10/2009 (10:51 pm)
The problem is that "SceneWindow2D.GetSceneGraph()" only works in functions that contain the window reference. For instance, it works fine in functions like "sceneWindow2D::onMouseDown()", but it doesn't work in normal functions.
#6
07/10/2009 (11:07 pm)
actually, it does. i've been using regular functions (say, not attached to a specific class), and using functions that has to do with SceneWindow2D (like cameraShake, getSceneGraph, setCurrentCameraZoom), and they work flawlessly... i dont see why it shouldnt, if the sceneWindow2D is something really global!.
Torque Owner Steve D
When you create an object just use the command %object.AddToScene(SG) and that should work just fine.
In the code you typed above, you are using %scenegraph which is a local variable and has no value assigned to it.