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

showing Icon on a 3D Screen

Last post 7/7/2009 7:38 PM by Lost Your Head Productions. 7 replies.
  • 7/7/2009 5:49 PM

    showing Icon on a 3D Screen

    I am wondering how to add a sprite to the gamescreen like a heath bar for instance
  • 7/7/2009 5:55 PM In reply to

    Re: showing Icon on a 3D Screen

    Simply by using the spriteBatch.Draw method to render it over the 3D game.
  • 7/7/2009 5:56 PM In reply to

    Re: showing Icon on a 3D Screen

    but will it stay on the screen when I mave aroung in 3D space
  • 7/7/2009 7:04 PM In reply to

    Re: showing Icon on a 3D Screen

    Divide your drawing into three phases:

    1) Draw all opaque 3D geometry. This uses the camera view and projection matrices, and the object world matrices.
    2) Draw all blended 3D geometry. Sort it from far-to-near to the camera. This makes sure that windows etc properly blend in order. Again, use the object world and the camera view and projection matrices.
    3) Draw all 2D/gui geometry. This uses screen space coordinates; the view/projection matrices com from the GUI system, not the camera.

    In general, you can place something anywhere you want on the screen with the appropriate transform matrices. After the projection matrix, the screen coordinates are X=-1 for left, X=1 for right, Y=-1 for bottom and Y=1 for top. Z=0 is the "near" plane, and Z=1 is the "far" plane, after Z has been divided by W. If you like this coordinate system, you can even emit vertices directly in this coordinate system, and set all the transform matrices to identity (or use a shader that doesn't transform through matrices at all).

    If you're unsure about how all this works, then I suggest reading up on the 3D graphics transform pipeline -- it's pretty much required knowledge when working with 3D graphics.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 7/7/2009 7:18 PM In reply to

    Re: showing Icon on a 3D Screen

    All I really want to know is if there is any other code needed to add a 2D sprite on the screen of a 3D game
  • 7/7/2009 7:24 PM In reply to

    Re: showing Icon on a 3D Screen

    Lost Your Head Productions:
    All I really want to know is if there is any other code needed to add a 2D sprite on the screen of a 3D game


    Nope. Just:

    spriteBatch.Draw(myTexture, new Vector2(0,0), Color.White);

    for instance.

    Edit: Well actually you need to load the texture before, so one more line of code...
  • 7/7/2009 7:27 PM In reply to

    Re: showing Icon on a 3D Screen

    Keep in mind that SpriteBatch modifies a number of render states that can affect your 3D drawing. So you need to make sure you restore any affected states after using the spritebatch.
  • 7/7/2009 7:38 PM In reply to

    Re: showing Icon on a 3D Screen

    ok all I need to know
Page 1 of 1 (8 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG