Jump to content
  • Advertisement
Sign in to follow this  
ProjectOlle

XNA creating a numberbar

This topic is 2595 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

Hey guys!

I want to have my 3D game, and in that game I want a simple HUD that displays things like your health and ammo etc. But I have no idea on how actually to "print" numbers to the screen ??

I know all about using sprites and stuff like that, but it seems stupid to have a 100 sprites to have numbers from 1-100 :P

I looked into some liberaries for HUDs but they are a little clumsy imo, and they tend to be very specific.. Anyone know of some methods in XNA that allow me to display variables on the screen or anything like that ? :)

Share this post


Link to post
Share on other sites
Advertisement
Well, if you really want just numbers and not other characters, that you could make 10 sprites (from 0-9) and draw those numbers.

Share this post


Link to post
Share on other sites

Well, if you really want just numbers and not other characters, that you could make 10 sprites (from 0-9) and draw those numbers.


True but I want numbers from 0-1000 :P so thats a lot of images just for that :P

I figured out the SpriteBatch.DrawString() method that almost solves my problem, now is there anyway to convert a int, float, double, to a string?? I tried casting to a char, and then a string but that wont work :(

Share this post


Link to post
Share on other sites
FIXED!!

Boy do I feel stupid now :P

here is the solution:

spriteBatch.Begin();
Vector2 FontOrigin = spriteFont.MeasureString(text) / 2;
spriteBatch.DrawString(spriteFont, yPos.ToString(), FontPos, Color.White, 0, FontOrigin, 1, SpriteEffects.None, 0.5f);

spriteBatch.End();


yPos is an int

Share this post


Link to post
Share on other sites
You can still print any numbers with a little logic (1000 is just two kinds of characters if you think about it), but you have found the solution anyway.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!