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

Sprite Sheets & Quadrangles - How do I draw the following?

Last post 10/20/2009 11:23 AM by fr3shme4t. 3 replies.
  • 10/18/2009 2:58 PM

    Sprite Sheets & Quadrangles - How do I draw the following?

    I have created a font/sprite sheet to using ttf2bmp:

    Right-click and select 'Set Image Properties'

    What I can't understand is how I would draw a quad with a "1" and "0" from the sprite sheet (bmp).

    I can draw a quad that has the whole sprite sheet as its texture, but I can't figure out how to take 2 separate locations on the sprite sheet and combine them to make a texture that is "10".

    Can someone please help?

    Thank you.
  • 10/19/2009 4:53 AM In reply to

    Re: Sprite Sheets & Quadrangles - How do I draw the following?

    You can use one of the SpriteBatch's Draw methods.

    SpriteBatch.Draw (Texture2D texture, Rectangle dest, Nullable<Rectangle> source, Color color)
    http://msdn.microsoft.com/en-us/library/bb196419.aspx

    This allows you to specify both the destination rectangle (where you draw on the screen) the source rectangle (what part of the texture you draw).

    So if character "1" is at pixel (5, 20) and is 16 pixels in size, and "0" is at (30, 20) and 8 pixels wide you can do this:
    // draw characers 1 and 0 next to each other 
    Draw(texture, new Rectangle(100, 100, 16, 16), new Rectangle(5, 20, 16, 16),  
    Color.White); 
    Draw(texture, new Rectangle(116, 100, 8, 16), new Rectangle(30, 20, 8, 16), Color.White); 

    Basically you create a source Rectangle for each character on your sheet and use than to draw your texture.
  • 10/19/2009 9:28 AM In reply to

    Re: Sprite Sheets & Quadrangles - How do I draw the following?

    I was thinking about drawing it in any location in a 3D world.  In this case would I have to render to texture using different uv coordinates from the sprite sheet and then display that texture?
  • 10/20/2009 11:23 AM In reply to

    Re: Sprite Sheets & Quadrangles - How do I draw the following?

    Yes, that's probably the simplest way to do it. 
    Create a render target, and then draw to it like I posted above, then just use that texture when you draw your object.

Page 1 of 1 (4 items) Previous Next