0
votes

I make a game using XNA. I would like to align sprite in the center of the screen. This works well when fullscreen is set to false. But when I set IsFullScreen to true, it doesn't work.

I activated the console and print the screen size on it. The size is good (1366 * 768). I also print the current position of the mouse pointer, and when I'm at the bottom right corner, it shows 1279*719, that's why my sprites are not center-align. Why ?

width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;

_positionStart = new Vector2(width * 0.5F - _startButton.Width * 0.5F, height * 0.5F - 20);

PS : I'm using XNA 4.0 with VS2012

PS2 : sorry for my grammar, I don't speak English fluently :)

2

2 Answers

2
votes

Probably because the top left corner of your sprite is drawn in the middle of the screen which means that the sprite will be drawn slightly on the right side and slightly lower too. Try values lover than 0.5, maybe 0,45, or even less. This should help.

2
votes

Well, if the other answer didn't work, a longer, but much more efficient way to do this would be too either:

  1. Set a Rectangle() to the object, and make that act as a bounding box, and use the .Center feature to align the center of it.
  2. Divide the height and the width by 2, as you did, but then minus half the height and width of the image itself (If you can't find that then just use a bounding box as above).

Hope this helps, I know this post is a bit old now, but someone else might stumble across this, and appreciate this answer!