What should i use for my 2D Game UI......

Started by
3 comments, last by Evil Steve 15 years, 7 months ago
I have been using a free framework that was designed for 2D games. I now realise that i can't add any true 3D to my game. So i have decided to create a new DirectX9 app. I don't want to use another framework as i want to learn how to do this. Can i make my 2D Game UI in DirectX9 using ID3DXSprite and is it recommended to do so, seems overkill to use something for 3D to do 2D? Any suggestions? Simple sample code that does the following properly would be great... My game code is separated from the free framework like so...


class MyObject{int x; int y; int width; int height; AN_IMAGE_CLASS* image; }; 

// then i do 
framework->Draw(MyObject->x,MyObject->y,MyObject->width,MyObject->height,MyObject->image);  

// it would be great if i could do something like....

MyObject windowFor3D;

// tell directx that any 3d should be rendered to this
// portion on screen
DirectX9->SetViewPort(&windowFor3D); 

// you can assume i have a 3d Terrain ready to render
DirectX9->Render3DStuffToThe3DWindow(); 

// now fill up the other parts of the screen with 2D UI
// here i would just go through a vector of MyObject's and
// draw each one using ID3DXSprite
DirectX9->Render2D_UI(); 

Advertisement
Quote:Original post by gameplayprogammer
I have been using a free framework that was designed for 2D games.
I now realise that i can't add any true 3D to my game.
So i have decided to create a new DirectX9 app.
I don't want to use another framework as i want to learn how to do this.
Can i make my 2D Game UI in DirectX9 using ID3DXSprite and is it recommended to do so, seems overkill to use something for 3D to do 2D? Any suggestions?

Simple sample code that does the following properly would be great...

My game code is separated from the free framework like so...

*** Source Snippet Removed ***


Is there really anything wrong with overkilling something? Just do what works for what you need.
This is your life, and it's ending one minute at a time. - Fight club
Quote:Original post by gameplayprogammer
Can i make my 2D Game UI in DirectX9 using ID3DXSprite and is it recommended to do so, seems overkill to use something for 3D to do 2D? Any suggestions?
It's fine. You're using a 3D API, it's more efficient to use 3D to render it, and you get stuff like free alpha blending and rotation that you couldn't easily get with a 2D API.

Rendering the API with a single ID3DXSprite sounds perfectly reasonable to me. If you find it isn't performant enough, it should be easy enough to write your own code to do the rendering instead of ID3DXSprite; particularly if you're keeping the ID3DXSprite code in one place (Where you go through the list of UI elements to draw and Draw() them).
Great, thanks for the replies, your answer has triggered a follow on question...

when you say...

"it should be easy enough to write your own code to do the rendering instead of ID3DXSprite"

what do you mean, write my own code? How can i render something to screen in my own code?
Quote:Original post by gameplayprogammer
Great, thanks for the replies, your answer has triggered a follow on question...

when you say...

"it should be easy enough to write your own code to do the rendering instead of ID3DXSprite"

what do you mean, write my own code? How can i render something to screen in my own code?
I meant managing a dynamic vertex buffer and submitting sprites yourself (Which is what ID3DXSprite does internally). It's unlikely you'll need to do such a thing though, ID3DXSprite is pretty performant as it is.

This topic is closed to new replies.

Advertisement