Reputation: 442
If i change the screen resolution then how i will get Change x and y position of an object:
For example my object current x position is 500 and y position is 100 and my current screen resolution is 1360*768
Now i change the screen resolution to 800*600
Then how i will get the changed x and y position of my object.
I am using the following formula to find the changed/updated x and y position:
x = (500 * 800) / 1360; y = (100 * 600) / 768;
But it is not giving Correct result to me, So please Help me to solve this problem.
Upvotes: 0
Views: 217
Reputation: 15881
You can try this formula...
1360 / 500
gives a ratio of 2.72. Knowing this ratio you can now use it like so:
800 / 2.72
= 294 (rounded to a whole number because there is no decimal points in pixel positions). Using the same above logic for height also you should have a final result like...
Stage Width = 1360 and Stage Height = 768
X-Pos = 500 and Y-Pos = 100
becomes...
Stage Width = 800 and Stage Height = 600
X-Pos = 294 and Y-Pos = 78
To round use myObject.x = int ( ratio_XPos_result )
Upvotes: 1