Quick and dirty way to display score on screen?
by Arden · in Torque Game Builder · 08/25/2010 (6:00 pm) · 5 replies
Hiya Folks, I'm looking for some basic pointers on how I can get score displayed on screen.
I figured the following code would do it. However, %scenegraph.addToScene(%textObject does not recognize the object. Am I approaching this in the right way, or is there a simpler way to do it?
Thanks for any help.
I figured the following code would do it. However, %scenegraph.addToScene(%textObject does not recognize the object. Am I approaching this in the right way, or is there a simpler way to do it?
Thanks for any help.
function mylevel::createTextGUI(%this)
{
echo ("initiated visualinfo::createTextGUI");
$scoreTag=%this.createTextTag();
$scoreTag.text="SCORE: ";
$scoreTag.setPosition(-39, -32);
$maxScoreTag=%this.createTextTag();
$maxScoreTag.text="H-SCORE: ";
$maxScoreTag.setPosition(-41, -27);
}
function mylevel::createTextTag(%this)
{
%textObject = new t2dTextObject()
{
scenegraph=%this;
size = "1.0 2.0";
font = "Arial";
wordWrap = "0";
hideOverflow = "0";
textAlign = "Left";
lineHeight = "2.0";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "80";
textColor="0.66";
}
};
%scenegraph.addToScene(%textObject);
return %textObject;
}
#2
08/25/2010 (6:25 pm)
Well, after commenting out the scenegraph line, it works for now (kind of). I guess I'm wondering at this point what addToScene is supposed to do, and if using scenegraph is necessary at all when manipulating text strings... I might end up solely using the editor like you suggested for now though.
#3
http://www.torquepowered.com/community/resources/view/19807
08/25/2010 (6:27 pm)
Found Patrick's code really easy and helpful. It's also good to look at...:)http://www.torquepowered.com/community/resources/view/19807
#4
08/25/2010 (7:48 pm)
Really nice! Got that implemented. Quick question: how do I reduce the size of t2dParticleEffect()? There's no method for that, so I guess I have to reduce the size of the linked images?
#5
@Arden, to reduce the size, you would want to reduce the size of the images and the 5 in the following line of code to match the new width.
It also may be possible to set the scale in the particle emitter, but you'll still need to adjust the above value in code to move the digits together.
By the way, I recently released another resource that I think is extremely useful, albeit unrelated.
08/26/2010 (1:45 am)
Always a thrill to see people using my resource!@Arden, to reduce the size, you would want to reduce the size of the images and the 5 in the following line of code to match the new width.
%xPos = getWord(%startPos, 0) + (%i * 5);This bit of code shifts the emitter for the next digit over, so decreasing the 5 will put the letters closer together.
It also may be possible to set the scale in the particle emitter, but you'll still need to adjust the above value in code to move the digits together.
By the way, I recently released another resource that I think is extremely useful, albeit unrelated.
Torque Owner Kevin James
Then you can reference it easily from code:
lblScore.text = 999;