FxTextObject2D and window creation
by Gregory Stewart · in Torque Game Builder · 09/11/2005 (9:10 am) · 3 replies
Ok, it's me again. This is driving me nuts. I'm using the fxTextObject2D resource and for some reason when I set the text, the rendering window is coming up as NULL, even though as far as I can tell, it should be active.
Here's how the code is getting called in client.cs:
Ok, now the createGameStatus() function:
Ok, and finally, I here's the C++ setTextAlignLeft(). Note that I've combined setText() with updateSize() for testing purposes:
Now, for some reason, the window is coming up as null. As far as I can tell, the window should currently be active, correct? Does anybody have any idea why this is happening?
Any help would be appreciated, thanks!
Here's how the code is getting called in client.cs:
function setupT2DScene()
{
...
// ************************************************************************
//
// Add your custom code here...
//
// ************************************************************************
createPlayer();
[b]createGameStatus();[/b]
}Ok, now the createGameStatus() function:
function createGameStatus()
{
%score = new fxTextObject2D() { scenegraph = t2dSceneGraph; };
%score.setFont( "Edit Undo Line BRK" );
%score.setSize( 24 );
%score.setPosition("-50 -36");
[b]%score.setTextAlignLeft( "SCORE" SPC 120000 );[/b]
%score.setFontColor("255 255 64 255");
}Ok, and finally, I here's the C++ setTextAlignLeft(). Note that I've combined setText() with updateSize() for testing purposes:
void fxTextObject2D::setTextAlignLeft( const char *text)
{
mTextString = StringTable->insert( text );
fxSceneWindow2D *window = Parent::getSceneGraph()->getCurrentRenderWindow();
// we don't have a render window yet, this requres it so wait until we do
[b]if(!window ) {
Con::printf( "setTextAlignLeft(): WARNING: WINDOW IS NULL");
return;
}[/b]
mStringFontSize.x=mpFont->getStrWidth(mTextString);
mStringFontSize.y=mpFont->getHeight();
// we need to convert the size from window to scene
Point2F cameraScale=window->getCurrentCameraScale();
Parent::setSize(fxVector2D(cameraScale.x*mStringFontSize.x,cameraScale.y*mStringFontSize.y ));
// adjust the position accordingly to align the text
Parent::setPosition( fxVector2D(getPosition().mX + (getSize().mX / 2), getPosition().mY) );
}Now, for some reason, the window is coming up as null. As far as I can tell, the window should currently be active, correct? Does anybody have any idea why this is happening?
Any help would be appreciated, thanks!
#2
That definitely helped a lot (you saved me many hours of confusion, again!)! Thanks again.
- Greg
09/11/2005 (10:15 am)
Thank you, Melv! I swear you are a machine. In any case, I was just browsing through the code, and I had a guess that something similar to what you described was probably what was happening, but I had not yet found the code to verify my guess. That definitely helped a lot (you saved me many hours of confusion, again!)! Thanks again.
- Greg
Associate Melv May
The problem is that the call doesn't make sense outside of the render call e.g. within "renderObject()". If you look at the "setCurrentRenderWindow()" usage, you'll see that any window that is currently rendering a scene, sets itself as the current render window and when it has finished, it sets it to NULL. Outside of rendering, the idea of a rendering window is ambiguous.
You can't refer to anything specific to a scene-window outside of rendering as multiple windows can render the same scene. You can, of course, refer to static things such as the canvas.
Hope this helps,
- Melv.