Quick Way to scale dimensions to the screenHeight
in
Android Processing
•
2 years ago
Hi guys... Basically I created this game here:
The problem I came across is scaling of typography and imagery to different screensizes as I wanted a universally hard gameplay.
so..... heres my (maybe) solution... nothing hard... just one function....
lets say you set the fontSize to 30 so:
- textSize(30);
and you have 2 phones... one with a screenHeight of 480 and another with 600...... how do we solve the problem of scaling?
this is the function i used to solve this issue and scale it on both phones:
- int scaleStuff(int newSize){
- newSize = screenHeight*newSize/<size of screen you are developing on>;
- newSize = int(newSize);
- return newSize;
- }
- textSize(scaleStuff(30));
Anyway... I think this can be improved..
Im sure there is a more developed solution for scaling but thats the best solution I could come up with!
thanks,
UPDATE:
Heres a more developed version that will work with either floats or integers
- // my sneaky scaling system for android.
- int scaleStuffByWidth(int newSize){
- float scaleSize = float(screenWidth)/<screen_width_size_you_are_developing_on.0>;
- float tempSize = newSize*scaleSize;
- newSize = int(tempSize);
- return newSize;
- }
- float scaleStufffByWidth(float newSize){
- float scaleSize = float(screenWidth)/<screen_width_size_you_are_developing_on.0>;
- float tempSize = newSize*scaleSize;
- newSize = tempSize;
- return newSize;
- }
- int scaleStuff(int newSize){
- float scaleSize = float(screenHeight)/<screen_height_size_you_are_developing_on.0>;
- float tempSize = newSize*scaleSize;
- newSize = int(tempSize);
- return newSize;
- }
- float scaleStufff(float newSize){
- float scaleSize = float(screenHeight)/<screen_height_size_you_are_developing_on.0>;
- float tempSize = newSize*scaleSize;
- newSize = tempSize;
- return newSize;
- }
1