Jump to content
  • Advertisement
Sign in to follow this  
ICUP

Centering an image and other formulas

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

What is the formula for centering an image? Or in other words, what is the formula to get the right x,y values to center an image (in pixels)? What are some other useful 2d formulas?

Share this post


Link to post
Share on other sites
Advertisement
Some questions... where is (0, 0) on the image, bottom-left, top-left, etc?
Do you have the width and height of the texture?

If so, just think about it, maybe draw a little picture on paper, that definitely helps visualize it.

Share this post


Link to post
Share on other sites
Of course 0,0 is the top most left. I tried something like this which I believe is the formula:

rect.x = SCREEN_WIDTH / 2;
rect.y = SCREEN_HEIGHT / 2;

However, this does not center the image...

Share this post


Link to post
Share on other sites
this?
rect.x = SCREEN_WIDTH / 2 - (rect.width / 2);
rect.y = SCREEN_HEIGHT / 2 - (rect.height / 2);

EDIT: nvm, you got it and someone posted before me lol. You just didn't take into account the width and height of the image.

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!