Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a top down Strategy/RPG/Tower Defense XNA Game for Windows, and I'm running into an issue while scaling.

My display mode is 1680 X 1050, and that is what I'm setting the PreferredBackBuffer width and height to.

What I'm finding is that when I use my camera object to zoom in and out (changing the scale on a matrix that is passed to the SpriteBatch.Begin method, it changes the scale of my sprites... but I'm still confined to the BackBuffer (0,0,1680,1050)...

Can I use something like a RenderTarget to extend the actual area that is accessible when zooming/panning across the "map"?

I'm looking at making it something like 5000 X 3125...

Any thoughts/examples of how I should approach this?

I've added a video of what I'm experiencing...

For the record I have also posted this question on Stack Exchange - Stack Overflow

share|improve this question
up vote 2 down vote accepted

If I understand you correctly, the coordinates you are getting from Mouse.GetState() always fall within the bounds of the screen (ie: 0 < x < 1680 and 0 < y < 1050).

This is normal.

The transformation matrix you are using is taking coordinates in "world space" and putting them in "client space" (which is the space that SpriteBatch then uses to project sprites onto the screen).

Mouse.GetState() also returns coordinates in client space. What you want is to find what position those client coordinates represent in world space. So what you have to do is reverse the transformation. Here is some (untested) code that shows you how:

MouseState mouseState = Mouse.GetState();
Matrix transform = whatever;
Matrix inverseTransform = Matrix.Invert(transform);
Vector2 clientMouse = new Vector2(mouseState.X, mouseState.Y);
Vector2 worldMouse = Vector2.Transform(clientMouse, inverseTransform);

(Note: If you get NaN errors, make sure you're not scaling your Z coordinate down to zero, see here.)

share|improve this answer
perfect. sorry it took so long to respond but that did it... I created a new method in my camera object that returns the inverse of the matrix and i just set my mouse position object to always be the inverse of the the transformation... works perfectly! – Patrick May 22 '13 at 0:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.