T2dTextObject and clone(%copyFields)
by David Boucugnani · in Torque Game Builder · 05/17/2007 (7:20 pm) · 2 replies
This is my first post and I'm really new at TGB (1.1.3) and TorqueScript in general.
Question: is the t2dTextObject clonable using the inherited t2dSceneObject.clone(%copyFields) method?
I have a TextObject defined in my level's Scene View, but out of the Camera View. Its not named, but has a class name. I'm setting the instance to a global as follows (I know I can name it, but wasn't sure about the clone-ability of a named object):
function EnemyTextTemplate::onLevelLoaded(%this, %scenegraph) {
$templateEnemyText = %this;
}
Then, later I'm trying to clone it as follows:
%enemyText = %templateEnemyText.clone(this);
%enemyText.setPosition(10,10);
But it doesn't appear in the scene after playing the level. The console doesn't report any problems.
But I can move the original into position using:
%templateEnemyText.setPosition(0,0);
and it appears in the scene.
Am I doing something wrong, or is this object not cloning as expected? BTW - I'm not quite ready to look into the source code myself yet.
Thanks.
Question: is the t2dTextObject clonable using the inherited t2dSceneObject.clone(%copyFields) method?
I have a TextObject defined in my level's Scene View, but out of the Camera View. Its not named, but has a class name. I'm setting the instance to a global as follows (I know I can name it, but wasn't sure about the clone-ability of a named object):
function EnemyTextTemplate::onLevelLoaded(%this, %scenegraph) {
$templateEnemyText = %this;
}
Then, later I'm trying to clone it as follows:
%enemyText = %templateEnemyText.clone(this);
%enemyText.setPosition(10,10);
But it doesn't appear in the scene after playing the level. The console doesn't report any problems.
But I can move the original into position using:
%templateEnemyText.setPosition(0,0);
and it appears in the scene.
Am I doing something wrong, or is this object not cloning as expected? BTW - I'm not quite ready to look into the source code myself yet.
Thanks.
#2
I wrote the following function and used it in place of directly calling the clone method. I can now clone the t2dTextObject at will!
So maybe the clone method in the underlying C++ class was not specialized for the t2dTextObject data members! Or something like that...
BTW - just wanted to say that TGB has been a great experience so far (just got it yesterday)! Thanks for making a great product! I hope to be getting into compiling and specializing it in Visual Studio before too long.
function t2dTextObjectClone(%parent) {
%myClone = %parent.clone(true);
%myClone.text = %parent.text;
%myClone.font = %parent.font;
%myClone.wordWrap = %parent.wordWrap;
%myClone.hideOverflow = %parent.hideOverflow;
%myClone.textAlign = %parent.textAlign;
%myClone.lineHeight = %parent.lineHeight;
%myClone.aspectRatio = %parent.aspectRatio;
%myClone.lineSpacing = %parent.lineSpacing;
%myClone.characterSpacing = %parent.characterSpacing;
%myClone.autoSize = %parent.autoSize;
%myClone.fontSizes = %parent.fontSizes;
return %myClone;
}
05/17/2007 (7:45 pm)
OK - I think I've got an answer:I wrote the following function and used it in place of directly calling the clone method. I can now clone the t2dTextObject at will!
So maybe the clone method in the underlying C++ class was not specialized for the t2dTextObject data members! Or something like that...
BTW - just wanted to say that TGB has been a great experience so far (just got it yesterday)! Thanks for making a great product! I hope to be getting into compiling and specializing it in Visual Studio before too long.
function t2dTextObjectClone(%parent) {
%myClone = %parent.clone(true);
%myClone.text = %parent.text;
%myClone.font = %parent.font;
%myClone.wordWrap = %parent.wordWrap;
%myClone.hideOverflow = %parent.hideOverflow;
%myClone.textAlign = %parent.textAlign;
%myClone.lineHeight = %parent.lineHeight;
%myClone.aspectRatio = %parent.aspectRatio;
%myClone.lineSpacing = %parent.lineSpacing;
%myClone.characterSpacing = %parent.characterSpacing;
%myClone.autoSize = %parent.autoSize;
%myClone.fontSizes = %parent.fontSizes;
return %myClone;
}
Torque Owner David Boucugnani
echo($templateEnemyText.class);
echo($templateEnemyText.text);
echo(%enemyText.class);
echo(%enemyText.text);
I get the following lines in the console:
enemyTextTemplate
1
enemyTextTemplate
This leads me to believe that the members of the t2dTextObject may not be getting copied...