convex-pixel
Version:
The library for creating pseudo 3d interactive scenes based on webgl
71 lines • 2.54 kB
JavaScript
import * as PIXI from "pixi.js";
import { BaseConvexObject } from "./base";
export class ConvexObject extends BaseConvexObject {
constructor(appContext, config) {
super(appContext, config);
this.appContext = appContext;
this._pointerOverHandler = () => {
this.pointerHover();
};
this._pointerOutHandler = () => {
this.pointerOutside();
};
this._pointerTapHandler = () => {
this.pointerTap();
};
}
setPOV(x, y) {
if (!this._displacementFilter) {
return;
}
const depth = this._config.isBackground ? 1 : this._config.depth;
this._displacementFilter.scale.x = x * depth * this.appContext.room.camera.maxZoom;
this._displacementFilter.scale.y = y * depth * this.appContext.room.camera.maxZoom;
}
/**
* Recalculation POV
* Repeat сalls are blocked
*/
recalculateCameraPOV() {
this.appContext.room.recalculateCameraPOV();
}
dispose() {
if (this._container) {
this._container.removeAllListeners();
}
super.destroy();
}
pointerHover() { }
pointerOutside() { }
pointerTap() { }
get originalWidth() {
const scale = this._container ? this._container.scale.x : 1;
return this._originalWidth * scale;
}
get originalHeight() {
const scale = this._container ? this._container.scale.y : 1;
return this._originalHeight * scale;
}
loadingComplete() {
if (!this._container) {
throw Error(`Propery "_container" is not defined.`);
}
if (this._config.interactive) {
this._container.interactive = Boolean(this._config.interactive);
if (this._config.hitArea) {
this._container.hitArea = new PIXI.Polygon(this._config.hitArea);
}
this._container.addListener("pointerover", this._pointerOverHandler);
this._container.addListener("pointerout", this._pointerOutHandler);
this._container.addListener("pointertap", this._pointerTapHandler);
}
// set pivot and scale
this._container.scale.x = this._container.scale.y = this._config.scale;
this.pivot.set(this.width * 0.5, this.height * 0.5);
super.loadingComplete();
}
get container() {
return this._container;
}
}
//# sourceMappingURL=convex-object.js.map