Jump to content
  • Advertisement
Sign in to follow this  
Slayus

Visual UI Timer

This topic is 2555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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?

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

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.

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
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

Share this post


Link to post
Share on other sites
What does the %i do and where does it come from? Plus is that a built in function that is in DirectX9?

Share this post


Link to post
Share on other sites

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"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!