I’ve finished making a game (simple 2D platformer) and I’m trying to improve some aspects of it. One of those aspects is making the game full screen. I unfortunately wrote the entire game with a 1440 x 900 window in mind so all of the object coordinates are fixed. After a lot of effort, I changed every single image position and size to a variable that’s depndant on the window size and height. Note that I want exactly everything that was present in the window to be present in full screen as well; literally stretching the window to full screen. Here is an example of what I did:
objects = new Object;
objects = new Cone(648);
objects = new Bin(1112, 1);
objects = new Sign(1536, 1);
objects = new Bench(2136);
objects = new Bus_Stop(2500);
objects = new Light(3400);
objects = new Car(3710, 2);
objects = new Bin(4744, 2);
objects = new Hydrant(5436);
objects = new Tree(5800);
objects = new Object;
objects = new Cone(width*0.45);
objects = new Bin(width*0.77, 1);
objects = new Sign(width*1.07, 1);
objects = new Bench(width*1.48);
objects = new Bus_Stop(width*1.74);
objects = new Light(width*2.36);
objects = new Car(width*2.58, 2);
objects = new Bin(width*3.29, 2);
objects = new Hydrant(width*3.77);
objects = new Tree(width*4.03);
Even though it works, I realize it isn’t a perfect solution as most, if not all, of the object positions (which is the first argument in every object, it’s the x coordinate) will be decimal so they’ll get rounded to a specific pixel as you can’t really print images using decimal pixels.
Is there a better way to implement full screen in a project or is this the only way?
yes that’s right because on a smartphone screen your objects won’t look the same as on desktop. That’s why you might need to scale your objects as well.
I scaled all of my objects already but I fear I might be doing it the wrong way. As shown in my code above, the way I do it is as follows:
an object that’s 64 x 64 in a resolution of 1440 x 900
will be 1920 / (1440/64) x 1080 / (900/64) in a resolution of 1920 x 1080
so the formula I use is width / (1440/object.width) x height / (900/object.height) which seems to work fine.
A problem I encountered is that when I move an object by just one pixel, that same movement option is not possible in other resolutions (since 1 pixel in 1440 x 900 won’t be the same as 1 pixel in 1920 x 1080 and I also can’t used decimal values for pixels) and I don’t know any workarounds for that.