1. Find the golden ratio (ideal height / window.innerHeight) (Or width, see 2nd point)
2. Resize the game in a way you either use entire height. To do that, divide your ideal height by golden ratio, then divide your ideal width with the golden ratio. (or do the opposite, if it doesn't fit like that. You can know this if width you get is larger than window.innerWidth)
3. Now, use your golden ratio to reinterpret where you would place your objects. x = 20 in a 1280x720 game becomes 10 in a 640x360 game. You get the golden ratio of 2 (720/360). 20 /2 = 10.
4. You have to use the golden ratio to reinterpret the scale too. In the above example, you would divide whatever scale you have by 2.
Tips:
1. Abstract away the phaser sprite as a component of your new Sprite type.
2. Use getters and setters when you send and receive values for the x and y properties of the sprite component. When you get them, divide it by the golden ratio and then change it in the sprite component. When you are asked for them, multiply from the value in the sprite component and send. Do save the original values privately.
3. Do the same for the scale.
4. Every resize updates everything.
5. Ensure that you don't deal with actual values directly, you have to always deal with assuming x = 20 (not 10), actual values should only work internally.
6. See the example of how to handle different values internally, and sending different values through getters.
get x() {
let gRatio = this._getGoldenRatio();
return this._sprite.x * gRatio;
}
get y() {
let gRatio = this._getGoldenRatio();
return this._sprite.y * gRatio;
}
set x(xVal) {
let gRatio = this._getGoldenRatio();
this._sprite.x = xVal / gRatio;
}
set y(yVal) {
let gRatio = this._getGoldenRatio();
this._sprite.y = yVal / gRatio;
}
EDIT:
Make sure to store golden ratios internally too, and when the global ratio changes (because of a resize) update everything. By x and y getters you would get ideal values, divide it by new golden ratio. Update values on the sprite component and then update the stored golden ratio.