Is there a way to re-size all the images inside the view port in a XNA project. At the moment when I re-size the view port the background stays at the same size of the image when I want it to re-size, this is the same for the different sprites. I have looked at different sources and I have not been able to find anything that has helped.


So effectively what you're illustrating in your question is that when you re size the viewport, all your sprites stay the same size, in the same location. It is imperative that you do not implicitly scale and position sprites with direct positions such as (0, -10) and scales such as (0.3f, 0.3f).

Instead you must take a scaling and positioning offset that is relational to the viewport size and scale. The reason for doing this is when you translate the application to another desktop resolution, the sprites will scale and position relative to this resolution.

A great example of the application of this is building a game on the iPhone and then finding all the sprites and UI break when ported to the iPad.

Position your sprites such as:

vec2 objPos = vec2(width*0.5f, height*0.5f);

Scale your sprites such as:

vec2 objScale = vec2(width*(0.2f*scaleWidthTuning)), height*(0.2f*scaleHeightTuning));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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