Centering an image and other formulas
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?
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.
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.
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...
rect.x = SCREEN_WIDTH / 2;
rect.y = SCREEN_HEIGHT / 2;
However, this does not center the image...
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement