Visual UI Timer

Started by
7 comments, last by yewbie 12 years, 9 months ago
I am trying to create a timer in my game that will print to the screen so that the player will know how long they have until the time runs out. I was thinking of making a sprite sheet of numbers and having my draw function cycle through the sprite sheet, printing each number to the screen.

Does anyone know an easier way to do this? I have a font function that can print words to the screen, but I cant get it to print numbers for some reason.

Thanks in advance for any help.
Advertisement
What does the font function do to print words out? Couldn't you follow the same logic to print numbers? Did you code the function, or does it come with an API? If it comes from an API, did you check the API's documentation?
What language and API are you probramming in?
I am using C++ with a DirectX wrapper. I did not create the font function either so I don't really know exactly how it does what it does. I have tried to edit it to print numbers, but to no avail.
Aha, well I'm trying to learn C++ and DirectX, so I don't think that I will be for much help. If it was C# and XNA, I could have helped you :wink:

I am trying to create a timer in my game that will print to the screen so that the player will know how long they have until the time runs out. I was thinking of making a sprite sheet of numbers and having my draw function cycle through the sprite sheet, printing each number to the screen.

Does anyone know an easier way to do this? I have a font function that can print words to the screen, but I cant get it to print numbers for some reason.

Thanks in advance for any help.

Can you use Microsoft's DirectWrite(Windows Vista and up) or ID3DXFont(DirectX 9.0)? Both are pretty easy to use.
I think what your wanting to do is write to a character buffer for instance say you have
int MyTimer = 5;
char Buffer[512];
sprintf_s(Buffer, 512, "Time left: %i", MyTimer);

then when you send some text to your font function just send Buffer like you would a string
What does the %i do and where does it come from? Plus is that a built in function that is in DirectX9?

What does the %i do and where does it come from? Plus is that a built in function that is in DirectX9?


Thats part of C, check of the reference for printf
http://www.cplusplus.../cstdio/printf/

The function I was using sprintf_s, takes as its 3rd argument what you want it to write to your buffer, also you can specific parameters for instance %i means we want an integer to be written to that spot, then the 4th parameter you supply your int, followed by whatever else you want written in that order so you could do something like this:

int Myint = 5;
char Mychar = 'c';
float Myfloat = 0.111;
char Buffer[512];
sprintf_s(Buffer, 512, "int: %i, char: %c, float: %f", Myint,Mychar,Myfloat);


That would output: "int: 5, char: c, float: 0.111"

This topic is closed to new replies.

Advertisement