Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
Have some resolution as a default, and draw everything at a scale of original dimensions * (user resolution/default resolution)? –  The Communist Duck Jan 2 '11 at 11:35
1  
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. –  Michael Coleman Jan 2 '11 at 23:55
    
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()); –  Leniency Jan 3 '11 at 3:42
    
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. –  Michael Coleman Jan 3 '11 at 22:05

1 Answer 1

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.

share|improve this answer
    
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. –  AttackingHobo Jan 2 '11 at 5:20
    
Ah, gotcha. I misunderstood what you were asking about. Editing answer to address that. –  Leniency Jan 2 '11 at 5:56
1  
I edited my question. I want to be able to render everything the same on all systems but scale it after the fact. –  AttackingHobo Jan 2 '11 at 15:23

Your Answer

 
discard

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.