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

Method updateTarget

packages/melonjs/src/camera/camera3d.ts:578–602  ·  view source on GitHub ↗

* Override Camera2d's 2D follow logic to additionally resolve * `followOffset` against the target's z. When `target` is set, the * camera's world position becomes `target.pos + followOffset`. * * **Semantic change vs Camera2d.follow:** this override **does not * honor `follow_axis`, `deadz

(dt?: number)

Source from the content-addressed store, hash-verified

576 * @ignore
577 */
578 override updateTarget(dt?: number): void {
579 const target = this.target;
580 if (target) {
581 // duck-type the z read via `'z' in target` so this works
582 // for both `Vector3d` (when the user passed a raw vector to
583 // `follow()`) and `ObservableVector3d` (when
584 // `follow(renderable)` assigned `renderable.pos`, which is
585 // observable not plain). The previous `instanceof Vector3d`
586 // check missed the observable variant — Renderable targets
587 // silently lost their depth.
588 const targetZ =
589 "z" in target && typeof target.z === "number" ? target.z : 0;
590 // Direct .x/.y assignment + `this.depth` (which proxies to
591 // pos.z) avoids the `as unknown as Pos3d` cast — Renderable
592 // already exposes `depth` as the proper z accessor.
593 this.pos.x = target.x + this.followOffset.x;
594 this.pos.y = target.y + this.followOffset.y;
595 this.depth = targetZ + this.followOffset.z;
596 this.isDirty = true;
597 return;
598 }
599 // no target — fall through to Camera2d's behavior (no-op when
600 // target is null)
601 super.updateTarget(dt);
602 }
603
604 /**
605 * Visibility check used by `Container.update` (in turn driving

Callers 4

runOneFrameFunction · 0.45
simulateFunction · 0.45
camera.spec.jsFile · 0.45
camera3d.spec.jsFile · 0.45

Calls

no outgoing calls

Tested by 2

runOneFrameFunction · 0.36
simulateFunction · 0.36