Sending functions to multiple sceneGraphs
by Don Hogan · in Torque Game Builder · 03/11/2006 (8:53 am) · 2 replies
Short description: I have a main t2dSceneWindow and sceneGraph for the game. Everything works nicely there.
I created a window in the GUI editor to use as a radar, then added a new t2dSceneWindow to it. In script, I assigned that one a unique sceneGraph, made a unique map for it and assigned it, and finally put in a triangle sprite for the player at 0,0.
All is still well to this point, and for the next baby step I want to do a simple rotation to match the players facing.
What I'm running into is that no matter how I've tried it, the update function is can't find the player's srpite in the radar sceneGraph.
...
And of course, now I can't recreate the error message to post, so can anyone tell be in general terms how to direct a function to a particular sceneGraph?
When I manage to re-create it, I'll post details.
Thanks,
Don
I created a window in the GUI editor to use as a radar, then added a new t2dSceneWindow to it. In script, I assigned that one a unique sceneGraph, made a unique map for it and assigned it, and finally put in a triangle sprite for the player at 0,0.
All is still well to this point, and for the next baby step I want to do a simple rotation to match the players facing.
What I'm running into is that no matter how I've tried it, the update function is can't find the player's srpite in the radar sceneGraph.
...
And of course, now I can't recreate the error message to post, so can anyone tell be in general terms how to direct a function to a particular sceneGraph?
When I manage to re-create it, I'll post details.
Thanks,
Don
#2
Yes, it was being overly tired that did it. The mistake was leaving out a set of brackets in a function call. I've fixed it here so this should work for anyone looking to implement this sort of feature.
** End edit. **
Thanks for the response, Luke.
I'll try to be pretty thorough, I fought this off and on all day yesterday and now I can't even get the error back. I should have left it alone when I was starting to get tired last night. =)
First, in client.cs
Then in scene.cs
The two HUD functions look like this:
That's all the sections I've been working with, I've been careful to make sure the second sceneGraph and radar elements are getting initialized before scene.cs tries to call them.
Thanks again,
Don
03/11/2006 (10:52 am)
** Edit: **Yes, it was being overly tired that did it. The mistake was leaving out a set of brackets in a function call. I've fixed it here so this should work for anyone looking to implement this sort of feature.
** End edit. **
Thanks for the response, Luke.
I'll try to be pretty thorough, I fought this off and on all day yesterday and now I can't even get the error back. I should have left it alone when I was starting to get tired last night. =)
First, in client.cs
function initialiseClient()
{
// Create t2dSceneGraph.
new t2dSceneGraph(Nebula9_01SceneGraph);
Nebula9_01SceneGraph.tag = "spacescene";
// Create a radar screen in the GUI
new t2dSceneGraph(playerRadarSceneGraph);
playerRadarSceneGraph.tag = "HUDradar";
*snip*
}Then in scene.cs
function setupT2DScene()
{
// Associate Scenegraph with Window.
Nebula9_01SceneWindow.setSceneGraph( Nebula9_01SceneGraph );
playerRadarSceneWindow.setSceneGraph( playerRadarSceneGraph );
createTestWorld();
createL01_Enemies();
createPlayerRadarHUD();
}
function t2dSceneGraph::onUpdateScene( %this )
{
*snip*
updatePlayerRadarHUD();
}The two HUD functions look like this:
function createPlayerRadarHUD()
{
%radar = new t2dTileMap() { scenegraph = playerRadarSceneGraph; };
%radar.loadTileMap("~/client/maps/playerRadarHUD.map");
%basicSpace = %radar.getTileLayer( 0 );
%basicSpace.setPosition( "0 0" );
%basicSpace.setTileSize( "5 5" );
%basicSpace.setLayer( 30 );
%basicSpace.setWrap( true, true );
playerRadarSceneWindow.setCurrentCameraPosition( "0 0", "20 15" );
// Create the player icon
$playerRadarIcon = new t2dStaticSprite() { scenegraph = playerRadarSceneGraph; };
$playerRadarIcon.setImageMap( redArrowImageMap );
$playerRadarIcon.setLayer( 20 );
$playerRadarIcon.setSize( "2 4" );
$playerRadarIcon.setPosition( "0 0" );
$playerRadarIcon.setRotation( $player.getRotation );
$playerRadarActive = false;
}
function updatePlayerRadarHUD()
{
$playerRadarIcon.setRotation( $player.getRotation() );
}That's all the sections I've been working with, I've been careful to make sure the second sceneGraph and radar elements are getting initialized before scene.cs tries to call them.
Thanks again,
Don
Torque 3D Owner Luke D
Default Studio Name
In general, if you have two properly set up SceneGraphs (each with their own window2D), if you create the sprite in the proper scenegraph, then you shouldn't have to worry about which one it's in to do stuff to it. For example, assuming two sceneGraphs exist already:
$playerSprite = new t2dAnimatedSprite() {scenegrah=playfieldSceneGraph;}; [stuff to set up sprite goes here] $radarSprite = new t2dStaticSprite() {scenegraph=radarSceneGraph;}; [stuff to set up sprite goes here] function t2dSceneGraph::onUpdateScene(%this) { $radarSprite.setRotation($playerSprite.getRotation()); }Is this similar to how you've implemented it?