Sign in to follow this  

Sprite Drawing (HUD)

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

Hi All, I'm relatively new to DirectX, so please excuse any striking stupidity on my part. I'm working on a simple 3D puzzle game with the basic code based largely around the Hazy Mind tutorials (http://www.thehazymind.com/3DEngine.htm). I have the 3D stuff working just fine...the problem is that I want to display some 2D buttons on the screen, sort of like a HUD, I guess. To do that, I'm attempting to use sprites, but can't seem to get them to actually draw on the screen. I have a simple GraphicsSprite class...
	public class GraphicsSprite
	{
		//statics
		private static readonly Vector3 Center = new Vector3(0,0,0);
		
		//instance data
		private Vector3 position;
		private float xUpdate = 1.4f;
		private float yUpdate = 1.4f;

		public GraphicsSprite(int posx, int posy)
		{
			position = new Vector3(posx,posy,1);
		}

		public void Draw(Sprite sprite, Texture t, Rectangle r)
		{
			sprite.Draw(t,r,Center,position,Color.White);
		}
	}
And I have these variable set up:
	private Texture spriteTexture = null;
	private Sprite sprite = null;
	private Rectangle textureSize;
	private GraphicsSprite newSprite = new GraphicsSprite(0,0);
I load the texture and such:
	spriteTexture = TextureLoader.FromFile(device, "mainbuttons.png");

	using(Surface s = spriteTexture.GetSurfaceLevel(0))
	{
		SurfaceDescription desc = s.Description;
		textureSize = new Rectangle(0,0,desc.Width,desc.Height);
	}
	sprite = new Sprite(device);
And attempt to draw it just after the 3D scene has been rendered, and before my optional FPS display is shown:
	myScene.Render(device);
			
	sprite.Begin(SpriteFlags.None);
	newSprite.Draw(sprite,spriteTexture,textureSize);
	sprite.End();

	ShowFPS();
I don't get any errors or anything, but I don't see any sprites, either. Everything else works fine. Any help is much appreciated. Thanks, Tom

Share this post


Link to post
Share on other sites
Correction! It is being drawn, but it's behind the 3D objects...I hadn't noticed that before, but moved the camera around, and there it was. How do I get the sprites to render in front of the 3D stuff? I'm calling it just before my call to device.EndScene() to no avail...

Thanks,
Tom

Share this post


Link to post
Share on other sites

This topic is 4110 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.

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