Sign in to follow this  
Slayus

Visual UI Timer

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
[quote name='Slayus' timestamp='1311085155' post='4837393']
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.
[/quote]
Can you use Microsoft's DirectWrite(Windows Vista and up) or ID3DXFont(DirectX 9.0)? Both are pretty easy to use.

Share this post


Link to post
Share on other sites
I think what your wanting to do is write to a character buffer for instance say you have
[code]int MyTimer = 5;
char Buffer[512];
sprintf_s(Buffer, 512, "Time left: %i", MyTimer);
[/code]
then when you send some text to your font function just send Buffer like you would a string

Share this post


Link to post
Share on other sites
[quote name='Slayus' timestamp='1311336957' post='4838868']
What does the %i do and where does it come from? Plus is that a built in function that is in DirectX9?
[/quote]

Thats part of C, check of the reference for printf
[url="http://www.cplusplus.com/reference/clibrary/cstdio/printf/"]http://www.cplusplus.../cstdio/printf/[/url]

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:

[code]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);[/code]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this