MCPcopy Create free account
hub / github.com/melonjs/melonJS / updateTarget

Method updateTarget

packages/melonjs/src/camera/camera2d.ts:605–654  ·  view source on GitHub ↗

@ignore

(dt?: number)

Source from the content-addressed store, hash-verified

603 /** @ignore */
604
605 updateTarget(dt?: number): void {
606 if (this.target) {
607 targetV.setV(this.pos);
608
609 switch (this.follow_axis) {
610 case this.AXIS.NONE:
611 //this.focusOn(this.target);
612 break;
613
614 case this.AXIS.HORIZONTAL:
615 targetV.x = this._followH(this.target);
616 break;
617
618 case this.AXIS.VERTICAL:
619 targetV.y = this._followV(this.target);
620 break;
621
622 case this.AXIS.BOTH:
623 targetV.x = this._followH(this.target);
624 targetV.y = this._followV(this.target);
625 break;
626
627 default:
628 break;
629 }
630
631 if (!this.pos.equals(targetV)) {
632 // update the camera position
633 if (this.smoothFollow && this.damping < 1.0) {
634 // account for floating precision and check if we are close "enough"
635 if (
636 toBeCloseTo(targetV.x, this.pos.x, 2) &&
637 toBeCloseTo(targetV.y, this.pos.y, 2)
638 ) {
639 this.pos.setV(targetV);
640 return;
641 } else {
642 // Frame-rate independent follow: re-anchor the parametric
643 // `damping` to a damp lambda at the engine's target rate.
644 const lambda = -Math.log(1 - this.damping) * timer.maxfps;
645 const dts = (dt ?? timer.step) / 1000;
646 this.pos.damp(targetV, lambda, dts);
647 }
648 } else {
649 this.pos.setV(targetV);
650 }
651 this.isDirty = true;
652 }
653 }
654 }
655
656 /** @ignore */
657 override update(dt?: number): boolean {

Callers 3

setDeadzoneMethod · 0.95
followMethod · 0.95
updateMethod · 0.95

Calls 6

_followHMethod · 0.95
_followVMethod · 0.95
toBeCloseToFunction · 0.90
setVMethod · 0.45
equalsMethod · 0.45
dampMethod · 0.45

Tested by

no test coverage detected