Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
See,I'm making a game for my computer project(in XNA 4).So,I do the programming at home and test it on the school computer in school.I placed several objects at many points in my game for example some at vector2(500,300),(700,1000) etc.All these items fit perfectly on my home computer's screen.But I noticed the the computer screen in my school is smaller so some objects do not appear in the school screen.How can I display all objects correctly and accurately on all screen sizes?Please help,its urgent.
Posted
Updated 1-Nov-14 22:07pm
v2
Comments
Kornfeld Eliyahu Peter 2-Nov-14 4:12am    
Do not put objects at fixed point but calculate position according to screen size...(use percentage)
Richard MacCutchan 2-Nov-14 4:17am    
That should be a solution, rather than comment.
swapnil999 2-Nov-14 4:21am    
can you reply with an example

"can you reply with an example"

Assuming your screen is 1000 pixels wide:

C#
int x = 700;                 // BAD!

int x = (WidthOfScreen * 700) / 1000;       // Better!

int xPercent = 70;
int x = (widthOfScreen * xPercent) / 100;   // Best!
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 2-Nov-14 4:46am    
How dare you! That's my solution!!!
(I believe you spent the morning doing some house-cleaning :-))
OriginalGriff 2-Nov-14 4:52am    
You didn't give an example! :laugh:

The cleaning is still going on - but slower now, thank goodness.
I think Protectors need the Power of BanHammer...it's pretty much the only way to get them to bugger off elsewhere...
Kornfeld Eliyahu Peter 2-Nov-14 4:56am    
When I came here yesterday it was bad but bearable...but the morning it was just terrible. I just reported and reported for 20 minutes, members and questions without any visible result! I just was unable to see any real question to answer!
Big thumb-up for you!
Afzaal Ahmad Zeeshan 2-Nov-14 5:48am    
I fixed a typo in your post, hopefully you don't mind.
Afzaal Ahmad Zeeshan 2-Nov-14 5:51am    
Using percentage values is a good idea, when you are going to target n number of screens. System would automatically detect the best screen size and the size for the objects. +5.
"in my game,I have drawn maybe 400-500 objects.Will I have to adjust all of them?It will surely take a lot of time."
You absolutely will want to find a "general" solution that will take care of scaling your Window (or whatever XNA calls its display), and all the objects in it. I bet that can be found.

I think you probably can get some help on an XNA programmer's forum. 'DreamInCode seems to be a very active one. A quick search turned up this likely resource: "Creating Resolution Independence For PC:" [^].
 
Share this answer
 
If you're not familiar with the different matrices used in rendering and their purpose then I suggest you do some reading. But generally speaking you should have a Model matrix, a View matrix and a Projection matrix.

The Model matrix represents the position of an object in the scene and is usually different for each object being rendered, unless the vertices are already in world space (ie, no transformation is necessary).
The View matrix represents you camera, so if you moved your camera to the right everything in the scene would appear to move left.
The Projection matrix transforms your 3D coordinates into Screen space (the 2D position on your screen).

If you want to render UI elements across a range of resolutions and aspect ratios you only need to update these matrices, instead of every single object.
The easiest way is to have the Model and View matrices as Identity matrices, and position all of your UI elements using screen space coordinates (which are between 0-1, or -1 and 1 I don't remember what XNA uses).

You would still need to handle changes in aspect ratio if you don't want things to be stretched.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900