1

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... http://www.youtube.com/watch?v=jIiAeXbAnec

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

Community
  • 1
  • 1
Patrick
  • 7,512
  • 7
  • 39
  • 50
  • Have you tried moving the entire world and not the camera? It should give the same effect and you wouldn't need to render a larger topology. – ericosg May 13 '13 at 06:09
  • I have... but it still doesn't help with the zooming... even though It zooms in and out, the mouse is still contained with in the scaled bounds of the viewport... I think I'm coming at it wrong... I'm considering scaling the sprites at the sprite level and not at the global level... – Patrick May 13 '13 at 13:34
  • I'm going to record a video of what is happening later this afternoon, a video is worth 10,000 words. – Patrick May 13 '13 at 13:35

1 Answers1

1

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.)

Community
  • 1
  • 1
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104