convex-pixel
Version:
The library for creating pseudo 3d interactive scenes based on webgl
62 lines • 2.18 kB
JavaScript
import * as PIXI from "pixi.js";
import { sonar as SonarUtils } from "../utils/package";
import { DomSynchronizer } from "./dom-synchronizer";
export class App {
constructor(config) {
this.tick = () => {
this.update();
};
SonarUtils.Sonar.create().run();
this._viewDomElement = config.view;
this.pixi = new PIXI.Application({
antialias: config.antialias,
transparent: config.transparent,
sharedLoader: config.sharedLoader,
sharedTicker: config.sharedTicker,
preserveDrawingBuffer: config.preserveDrawingBuffer,
resolution: config.resolution,
forceCanvas: config.forceCanvas,
backgroundColor: config.backgroundColor,
clearBeforeRender: config.clearBeforeRender,
forceFXAA: config.forceFXAA,
autoDensity: config.autoDensity,
powerPreference: config.powerPreference,
resizeTo: config.resizeTo,
width: config.width,
height: config.height,
});
this._domSynchronizer = new DomSynchronizer(this);
this._viewDomElement.appendChild(this.pixi.view);
this.pixi.ticker.add(this.tick, 9999);
}
get room() {
return this._room;
}
get domSynchronizer() {
return this._domSynchronizer;
}
setRoom(room) {
this._room = room;
}
destroy() {
SonarUtils.Sonar.instance.destroy();
this.pixi.destroy();
}
update() {
let needResize = false;
if (this.pixi.view.width !== this._viewDomElement.offsetWidth) {
this.pixi.view.width = this._viewDomElement.offsetWidth;
needResize = true;
}
if (this.pixi.view.height !== this._viewDomElement.offsetHeight) {
this.pixi.view.height = this._viewDomElement.offsetHeight;
needResize = true;
}
if (needResize)
this.resize(this.pixi.view.width, this.pixi.view.height);
}
resize(width, height) {
// etc
}
}
//# sourceMappingURL=app.js.map