Displaying text

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
isiahil

Displaying text

Post by isiahil »

I am trying to make a FPS and need to draw big font for the HUD. I need to know how do i display text for things like the bullets(which changes values whenever shot) and life. I need like a size 16 font. Please post some sample code
Nessie
Posts: 14
Joined: Thu Apr 08, 2004 4:27 pm
Location: Madison, WI, USA

Post by Nessie »

Code: Select all

IGUIEnvironment* guienv = gDevice->getGUIEnvironment();

// If you keep a pointer to bulletStat you can just change the text when you want.
IGUIStaticText *bulletStat = guienv->addStaticText(L"", rect<int>(5,-2,640,38), false);

// set custom font...The irrLicht download contains a font generation tool, in the Tools folder
IGUISkin *skin = guienv->getSkin();
gui::IGUIFont* font = gDevice->getGUIEnvironment()->getFont("font.bmp");
skin->setFont( font );

// you could call something like this whenever the bullet count changes
wchar_t tmp[320];
swprintf(tmp, 320, L"Bullets: %i", bulletCount);
bulletStat->setText(tmp);
"Build a man a fire and he'll be warm for the evening. Set a man on fire and he'll be warm for the rest of his life." -unknown
isiahil

Post by isiahil »

When i use that code when the bulletcount changes the old number stays in the box so after awhile the text in the box is all messy and u can't see anything. Is there anyway to clear the box before drawing the new number in it?
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

Code: Select all

// If you keep a pointer to bulletStat you can just change the text when you want. 
IGUIStaticText *bulletStat = guienv->addStaticText(L"", rect<int>(5,-2,640,38), false); 
Read the comment :) I'm guessing that you've pasted that code in and you're creating a new static text element every time the HUD changes - instead just create the static text once when your application loads and store the pointer to it. Then when you need to modify the text, use nessie's code:

Code: Select all

wchar_t tmp[320]; 
swprintf(tmp, 320, L"Bullets: %i", bulletCount); 
bulletStat->setText(tmp); 
isiahil

Post by isiahil »

The text is kind of transparent, how do i make it more opaque?
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

Check the documentation for a function

Code: Select all

IStaticText::setOverrideColor(SColor)
greetings, rincewind
Post Reply