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

Method setPosition

packages/planck-adapter/src/index.ts:656–670  ·  view source on GitHub ↗
(renderable: Renderable, p: Vector2d)

Source from the content-addressed store, hash-verified

654 }
655
656 setPosition(renderable: Renderable, p: Vector2d): void {
657 const body = this.bodyMap.get(renderable);
658 if (body) {
659 // `p` is in renderable.pos space (typically top-left). The body
660 // is anchored at the shape centroid; convert via the cached
661 // offset so syncFromPhysics keeps renderable.pos at the
662 // requested value.
663 const off = this.posOffsets.get(renderable);
664 const wpx = p.x - (off?.x ?? 0);
665 const wpy = p.y - (off?.y ?? 0);
666 body.setTransform(this.vec2InMeters(wpx, wpy), body.getAngle());
667 }
668 renderable.pos.x = p.x;
669 renderable.pos.y = p.y;
670 }
671
672 setAngle(renderable: Renderable, angle: number): void {
673 const body = this.bodyMap.get(renderable);

Callers

nothing calls this directly

Calls 4

vec2InMetersMethod · 0.95
getMethod · 0.65
getAngleMethod · 0.65
setTransformMethod · 0.45

Tested by

no test coverage detected