# Sprites in DirectX9

This topic is 3928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently writing a button class, and are a class for handling all my buttons in a game I'm working on. I wonder, what is the best way to make this class? Input are going trough the mouse, dont know if im going to use direct input or the windows handler. The buttons graphics are drawn with a sprite, and when I initiate the class, i send in the buttons dimentions( if the user clicks within that buttons dimentions, the action will happen ) The sprite draws just nice, but when I change screen res within the code, the sprite maintains the size it had( probably sized according my desktops screen rez ). This makes it incorrect to run the game on systems with other than screenrez 1024*768 on the desktop. How can I correct this problem? How can I make it follow the screenres within my game, and not my desktop? Or should I do this in a completly other way? This is how I render the sprite: D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vPosition( this->X, this->Y, 0.0f ); m_pSprite->Draw( m_pButtonTexture.getTexture(), NULL, &vCenter, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) ); Thanks, digitalerr0r

##### Share on other sites
You may scale sprite to fit new resolution.
Sprite whatever resolution you have stay same size. Whether your resolution
800x600 or 1600x1200, 300x300 size pixel don't change their size.
But you can scale or rotate sprite. That's the complicated way [smile].
On the other hand you can draw simple quads, that will remain same dimension aspect even if you change resolution.
Two triangle, and problem is solved.

##### Share on other sites
Yeah, maby I will make it a quad. But I have to use Screen Space then, for easier mouse detection within the buttons space. What is the easiest way to use a screenspace coordinate system? Will screenspace use the desktops resolution, or the one i specify within the application?

##### Share on other sites
Quote:
 Original post by digitalerr0rYeah, maby I will make it a quad. But I have to use Screen Space then, for easier mouse detection within the buttons space. What is the easiest way to use a screenspace coordinate system? Will screenspace use the desktops resolution, or the one i specify within the application?

I use combined version. Ortho graphic that mimics sprites drawing, and one routine that checks if wm_mousemove + wm button messages, are clicked within the given quad.
Fast as hell.
Screenspace is one you defined with application.

##### Share on other sites
Quote:
 Yeah, maby I will make it a quad. But I have to use Screen Space then, for easier mouse detection within the buttons space. What is the easiest way to use a screenspace coordinate system? Will screenspace use the desktops resolution, or the one i specify within the application?

You can avoid troubling your self with screen space. Create a quad and define each vertex to have its fixed position values.

struct FixedVertex{     float fX, fY, fZ, fW;     ...     ...}#define FIXEDVERTEX_FVF D3DFVF_XYZRHW | ...

intialize fW to 1 whenever needed.

This way fX = 100, fY == 200 means that at this point exactly on the screen the vertex will be placed.

##### Share on other sites
Thanks for the replies! I got it solved now, using fixedpoint :)