the-world-engine
Version:
three.js based, unity like game engine for browser
54 lines (52 loc) • 1.37 kB
JavaScript
import { Vector2, Vector3 } from "three/src/Three";
import { Component } from "../../hierarchy_object/Component";
export class ParallaxTranslater extends Component {
disallowMultipleComponent=true;
Xo=1.5;
Yo=1.5;
Jo=true;
Qo=new Vector2;
start() {
if (this.Jo) {
this.Qo.set(this.transform.localPosition.x, this.transform.localPosition.y);
}
}
qn=new Vector3;
xh=new Vector2;
update() {
const t = this.qn.copy(this.engine.cameraContainer.camera.transform.position);
const e = this.transform.parent;
const i = e ? e.inverseTransformPoint(t) : t;
const s = this.xh.set(i.x, i.y);
const r = s.x - this.Qo.x;
const o = s.y - this.Qo.y;
const n = this.Xo * r;
const h = this.Yo * o;
this.transform.localPosition.x = this.Qo.x + n;
this.transform.localPosition.y = this.Qo.y + h;
}
get offsetX() {
return this.Xo;
}
set offsetX(t) {
this.Xo = t;
}
get offsetY() {
return this.Yo;
}
set offsetY(t) {
this.Yo = t;
}
get initializeCenterFromPosition() {
return this.Jo;
}
set initializeCenterFromPosition(t) {
this.Jo = t;
}
get center() {
return this.Qo;
}
set center(t) {
this.Qo.copy(t);
}
}