workadventure/front/src/Phaser/Login/ResizableScene.ts

21 lines
755 B
TypeScript
Raw Normal View History

2021-09-06 14:27:54 +02:00
import { Scene } from "phaser";
2021-05-05 17:07:03 +02:00
import DOMElement = Phaser.GameObjects.DOMElement;
2020-10-07 18:03:34 +02:00
export abstract class ResizableScene extends Scene {
public abstract onResize(): void;
2021-05-05 17:07:03 +02:00
/**
* Centers the DOM element on the X axis.
*
* @param object
* @param defaultWidth The width of the DOM element. We try to compute it but it may not be available if called from "create".
*/
public centerXDomElement(object: DOMElement, defaultWidth: number): void {
2021-09-06 14:27:54 +02:00
object.x =
this.scale.width / 2 -
(object && object.node && object.node.getBoundingClientRect().width > 0
? object.node.getBoundingClientRect().width / 2 / this.scale.zoom
: defaultWidth / this.scale.zoom);
2021-05-05 17:07:03 +02:00
}
2020-10-07 18:03:34 +02:00
}