Search code examples
actionscript-3apache-flexflex4

How to Calculate Scale Factor if Screen Resolution Will Change in AS3


If i change the screen resolution then, how I will calculate the Change Scale Factor of an object :

For example my object current this.scaleX is 0.8 , this.scaleY is 0.8 (as you know scaleX and scaleY are the properties of the Flex) and my current screen resolution is 1360*768

Now I change the screen resolution to 800*600 ,

Then how I will calculate the changed scaleX and scaleY of my object.

I am using the following formula to find the changed/updated Scale Factor :

scaleX = scaleX * (768 / 1360) * (800 / 600);

scaleY = scaleY * (768 / 1360) * (800 / 600);

But it is not giving Correct result to me,

So please Help me to solve this problem.


Solution

  • To calculate the scale of an axis you only need to take into account the values of that axis on the screen. So either X (width) or Y (height), but not both. Also I would use the width and height of the screen at a scale of 1 as reference values. This will make it easier to calculate the new scale. In your case:

    screenWidthAtFullScale = 1360 / 0.8
    screenHeightAtFullScale = 768 / 0.8
    scaleX = 800 / screenWidthAtFullScale => 0.47
    scaleY = 600 / screenHeightAtFullScale => 0.625
    

    Note that this will distort your object. It would be better to calculate one scale and apply that to both the X and Y axis to prevent that.