XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

How do I place a black border around my sprite font?

Last post 04-16-2008 8:34 PM by Shawn Hargreaves. 9 replies.
  • 04-08-2008 5:25 PM

    How do I place a black border around my sprite font?

    Hi,

    I'm currently trying to figure out how I can place a black border around a sprite font that I created using the .TTF to .BMP converter.  I got the font loaded into the game just fine, but, I just can't figure out what to do to make it have a black border (or any color for that matter).  Also, I would like to place borders around sprites in general if there is an easy way to do it with code.

    Thanks,
    Tim
  • 04-08-2008 5:38 PM In reply to

    Re: How do I place a black border around my sprite font?

    One easy way is to draw the sprite (or character) 5 times.

    Draw it one pixel up, down, left, right with the color set to black and then draw it once in the right place with the color set to white.



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 04-08-2008 5:54 PM In reply to

    Re: How do I place a black border around my sprite font?

    You could always try drawing just two copies of your sprite and scaling one of them so that it is smaller or larger then the other. Doing this though you would need to make sure that you draw the larger one first then the smaller one.
  • 04-08-2008 6:43 PM In reply to

    Re: How do I place a black border around my sprite font?

    Glenn Wilson:
    You could always try drawing just two copies of your sprite and scaling one of them so that it is smaller or larger then the other.

    Adding to that, if you set the origin to the center of the texture, you can use the same position for both of them.
  • 04-09-2008 3:27 AM In reply to

    Re: How do I place a black border around my sprite font?

    I'm not sure this will work well. Assuming that the font image has all character in one image, he has to do one scale per character, centering the scaling on the center of the char. An actually this will not even work very well, since beveling a contour and scaling are two different operations. Best, meme
  • 04-09-2008 5:15 AM In reply to

    Re: How do I place a black border around my sprite font?

    Actually yeah, you're right.  Especially if there is a transparent section in the middle of the sprite, that part wouldn't be outlined the right way.  I didn't think about that.
  • 04-09-2008 12:50 PM In reply to

    Re: How do I place a black border around my sprite font?

    Drawing the text a couple of times tinted black with slight offsets in different directions, then once at the exact position in the color you really want, will work well.

    Even easier, you could just bake the outline into your sprite bitmap before you build the font. Photoshop has filters that can do such things, or you could use something like this.
    XNA Framework Developer - blog - homepage
  • 04-09-2008 2:07 PM In reply to

    Re: How do I place a black border around my sprite font?

    Shawn Hargreaves:
    Photoshop has filters that can do such things

    Yep, just go to the blending options at the bottom of the layers panel, then click on 'Stroke' you can set which color you want the outline to be, how thick it is, or you can even make the border see-through.
  • 04-16-2008 8:03 PM In reply to

    Re: How do I place a black border around my sprite font?

    How do you access the sprite bitmap for editing?  Right now I have XNA importing the TrueType font directly into an .xnb file.

  • 04-16-2008 8:34 PM In reply to

    Re: How do I place a black border around my sprite font?

    David Flook:

    How do you access the sprite bitmap for editing?  Right now I have XNA importing the TrueType font directly into an .xnb file.



    http://blogs.msdn.com/shawnhar/archive/2007/04/26/bitmap-fonts-in-xna.aspx
    XNA Framework Developer - blog - homepage
Page 1 of 1 (10 items) Previous Next