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

Function strokeBodyVelocity

packages/debug-plugin/src/patches.js:163–184  ·  view source on GitHub ↗

* Stroke a blue velocity arrow from `(originX, originY)` along the * body's current velocity vector. Scales by `(hW, hH)` so the arrow * length is visually proportional to the body's size regardless of * scale. Skips the draw entirely (and the counter increment) when * the body is at rest. Used

(
	renderer,
	panel,
	adapter,
	renderable,
	originX,
	originY,
	hW,
	hH,
)

Source from the content-addressed store, hash-verified

161 * @param {number} hH
162 */
163function strokeBodyVelocity(
164 renderer,
165 panel,
166 adapter,
167 renderable,
168 originX,
169 originY,
170 hW,
171 hH,
172) {
173 const v = adapter.getVelocity(renderable, sharedBodyVel);
174 if (v.x === 0 && v.y === 0) {
175 return;
176 }
177 renderer.save();
178 renderer.lineWidth = 1;
179 renderer.setColor("blue");
180 renderer.translate(originX, originY);
181 renderer.strokeLine(0, 0, Math.trunc(v.x * hW), Math.trunc(v.y * hH));
182 panel.counters.inc("velocity");
183 renderer.restore();
184}
185
186/**
187 * Monkey-patch melonJS rendering classes to draw debug overlays

Callers 1

applyPatchesFunction · 0.85

Calls 7

incMethod · 0.80
getVelocityMethod · 0.65
saveMethod · 0.45
setColorMethod · 0.45
translateMethod · 0.45
strokeLineMethod · 0.45
restoreMethod · 0.45

Tested by

no test coverage detected