need help outputting text to HUD

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
DriftRS
Posts: 8
Joined: Mon May 22, 2006 7:21 am

need help outputting text to HUD

Post by DriftRS »

I'm attempting to make a little HUD which outputs the number of fairies collected (yes we are going to change them to something other then fairies latter :P) However I'm running accross alot of problems, mainly the text likes to output itself on the top of already made text.

With my limited knowledge from 2 days of using irrlicht, I've tried coding it as below

Code: Select all

wchar_t* hub_text = L"Faeries Collected: ";
				hub_text += fairies_collected;

				gui::IGUIStaticText* collected = env->addStaticText(
					hub_text,
				core::rect<s32>(0,0,300,300), true, true, 0, -1, true);
I've also tried a number of other ways of setting out the code, at best it simply writes the new textbox over the old one instead of just updating it, at worst it crashes after collecting a single fairy. The other problem is the little pale window the text likes to appear in, maybe static text boxes just arn't the right way to do this... oh, and of course I've set up the variable liek this as global:

Code: Select all

gui::IGUIStaticText* collected = NULL;
Thanks in advance for any help :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you just think about your problem and read the method name addStaticText you should not wonder why this is happening. You cannot update a text by always creating a new one, unless you removed the old one. This is not really Irrlicht specific, but common programming practice (it even works in real life :wink: ) So just use the text you create once in the beginning and replace its text with some method (e.g. collected->setText(something), please read the API for the correct method name).
toc
Posts: 5
Joined: Mon May 22, 2006 3:17 am

Post by toc »

Thanks for the reply (I'm working with DriftRS on this). What you said sort of just 'clicked' with us before we even got to reading your post. Still can't figure out how we managed to miss that blunder...

In any case, the main problem now is we're not sure how to generate a string to be displayed in the hub. The following just outputs "Fairies Collected: " (with no number).

wchar_t* hub_text = L"Faeries Collected: ";
hub_text += fairies_collected;

After looking around online I found a site (http://www.unet.univie.ac.at/aix/libs/b ... printf.htm) which mentioned wsprintf, which sounded like it'd work for this. Unfortunately, Visual C++ keeps telling me that there's no such method as wsprintf (even when I include the wchar.h header file).

wchar_t* hub_text;
wsprintf(hub_text, "Faeries Collected: %d", fairies_collected);


Is this the right way to be going about it, or am I completely missing the mark? :S

Thanks in advance!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I think it's swprintf(...) and not wsprintf(...) !!! ;)

Code: Select all

wchar_t* hub_text;

swprintf(hub_text, L"Faeries Collected: %d", fairies_collected);
txtNode->setText(hub_text);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Your original code shoudl work a s well, since irrString has a method to convert integers to strings.
toc
Posts: 5
Joined: Mon May 22, 2006 3:17 am

Post by toc »

Acki wrote:I think it's swprintf(...) and not wsprintf(...) !!! ;)
Oh. :oops:

You appear to be right. Well, its working now (tends to help if you call the correct function :P).

Thanks again!
Post Reply