handle resize

This commit is contained in:
ajuvercr 2019-09-21 20:19:31 +02:00
parent 1b66d6289b
commit 4a8a9185af

View file

@ -142,6 +142,10 @@ class GameInstance {
SLIDER.max = this.turn_count - 1 + ''; SLIDER.max = this.turn_count - 1 + '';
} }
on_resize() {
this.resizer = new Resizer(CANVAS, [...f32v(this.game.get_viewbox(), 4)], true);
}
_update_state() { _update_state() {
const colours = f32v(this.game.get_planet_colors(), this.planet_count * 6); const colours = f32v(this.game.get_planet_colors(), this.planet_count * 6);
for(let i=0; i < this.planet_count; i++){ for(let i=0; i < this.planet_count; i++){
@ -276,6 +280,15 @@ export async function set_instance(source: string) {
set_loading(false); set_loading(false);
} }
window.addEventListener('resize', function() {
CANVAS.width = CANVAS.getBoundingClientRect().width;
CANVAS.height = CANVAS.getBoundingClientRect().height;
if (game_instance) {
game_instance.on_resize();
}
}, { capture: false, passive: true})
SLIDER.oninput = function() { SLIDER.oninput = function() {
if (game_instance) { if (game_instance) {
game_instance.updateTurn(parseInt(SLIDER.value)); game_instance.updateTurn(parseInt(SLIDER.value));