Jump to content
  • Advertisement
Sign in to follow this  

Sprite offset after scaling...

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



I'm trying to draw some simple sprites 'on top' of my 3d scene (sort of HUD idea).

But I've been struggling about 2 hours on the following:


- when the scale is 1.0f, the position is as expected.

I pass a screen position X/Y, of which I expect it to be the top left corner of the sprite

- when I take a lower scale, the scaling works, but the position is somehow altered too.

I suspect this is because of the scalingcenter


Conclusion; the more I adjust the scale, the more the sprite 'moves' on the screen.

Or better explained: the given pX and pY are no longer the resulting screen positions of the top left corner of the sprite.


I've been calculating and trying to find the equation to find out what's happening, but no success yet.


Do you have any idea?


Here's the code:

D3DXVECTOR2 trans((float)pX, (float)pY);
D3DXVECTOR2 spritecenter((float)(mWidth * mDefaultScale.x / 2.0f), (float)(mHeight * mDefaultScale.y / 2.0f));

D3DXMatrixTransformation2D(&mat, &D3DXVECTOR2(0.0f, 0.0f), 0.0f, &mDefaultScale, &spritecenter, DEGTORAD(pRotationDeg), &trans);

// set matrix and draw sprite
mSpriteObj->Draw(mTexture, NULL, NULL, NULL, mDefaultColor);

Edited by cozzie

Share this post

Link to post
Share on other sites

You've gotta be kinding me.... It was working all the time.


Guess what, I'm testing in windowed mode, where the say 5 or 10 pixels are used by the window border (I assume). Since it all works perfect in fullscreen.

Share this post

Link to post
Share on other sites
when you created your window did you use the AdjustWindowRect method? that will give you your screen with the borders and other window features accounted for.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!