7
\$\begingroup\$

I am trying to figure out the best way to render a 2d game at any resolution.

I am currently rendering the game at 1920x1200. I am trying scale the game to any user selected resolution without changing the way I am rendering, or game logic.

What is the best way to scale a game to any arbitrary resolution?

Edit: I am trying to achieve this:

http://www.david-amador.com/2010/03/xna-2d-independent-resolution-rendering/

but I think the code he has is for a different version of XNA because I cannot find that method overload he uses.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Have some resolution as a default, and draw everything at a scale of original dimensions * (user resolution/default resolution)? \$\endgroup\$ Commented Jan 2, 2011 at 11:35
  • 1
    \$\begingroup\$ Are you looking for the SpriteBatch.Draw overload? If your using XNA 4.0, you have to use this one for the transformation matrix : msdn.microsoft.com/en-us/library/ff433701.aspx It's the last argument. Next time, try specifying the actual code. \$\endgroup\$ Commented Jan 2, 2011 at 23:55
  • \$\begingroup\$ Reading through the example code, I got it to work with only changing one line in the Draw function - the parameters for SpriteBatch.Begin changed in 4.0: spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Resolution.getTransformationMatrix()); \$\endgroup\$
    – Leniency
    Commented Jan 3, 2011 at 3:42
  • \$\begingroup\$ You could also render to a render target and then just scale that. Just another way to go about it. (not really sure about efficiency) I don't think it would be a terrible problem. \$\endgroup\$ Commented Jan 3, 2011 at 22:05

1 Answer 1

4
\$\begingroup\$

Edit:

You're looking for the SpriteBatch.Draw(Texture2D, Rectangle, Color) call. The Rectangle represents the scaled draw target on the screen.

I'm assuming here that you're not using a grid layout - wasn't specified in the question so I'll go with assets being able to be drawn at any pixel rather than on a set grid.

  1. First decide on what should be 'native' resolution. Probably just height though, different monitors have different aspect ratios so that'll have to be accounted for. Lets pick 1200 as the native height. All scaling will be based off this number.

  2. Say I'm running the game on my TV with only 720p - 60% of the height. All unit coordinates and the Rectangle sizes then should be multiplied by 0.6. A hypothetical orc unit is 20 pixels tall and located at (50,45) under native resolution. At draw time, the target Rectangle would become 12 pixels tall and drawn at (30, 27)

  3. Where exactly you calculate in the scaling may be an issue. You can run the game entirely as if it were running at native resolution - this would mean no extra scaling in things like distance computations, animation speed and interpolation, etc... Then, only do the scaling at draw time, or with hit testing mouse clicks. If you chose to scale everything, then you just need to make that scale accessible to all systems globally and remember to account for it.

Hope this answers your question better.

\$\endgroup\$
3
  • \$\begingroup\$ I want to scale my game without having to draw it differently. You just told me how to change the resolution. If I just change the resolution it wont change the scale, it will just change the size of the game, which is what I don't want. \$\endgroup\$ Commented Jan 2, 2011 at 5:20
  • \$\begingroup\$ Ah, gotcha. I misunderstood what you were asking about. Editing answer to address that. \$\endgroup\$
    – Leniency
    Commented Jan 2, 2011 at 5:56
  • 1
    \$\begingroup\$ I edited my question. I want to be able to render everything the same on all systems but scale it after the fact. \$\endgroup\$ Commented Jan 2, 2011 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .