perf: use cached body dimensions in tick, remove redundant style sets
This commit is contained in:
@@ -192,36 +192,23 @@ export class GravityEngine {
|
||||
|
||||
this.bodies.forEach((body) => {
|
||||
if (body.isDragging) {
|
||||
// Only update visually while dragging, physics are paused
|
||||
body.el.style.position = "fixed";
|
||||
body.el.style.left = "0px";
|
||||
body.el.style.top = "0px";
|
||||
body.el.style.transform = `translate(${body.x}px, ${body.y}px)`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply Gravity
|
||||
body.vy += gravity;
|
||||
body.x += body.vx;
|
||||
body.y += body.vy;
|
||||
|
||||
// Apply Air Friction
|
||||
body.vx *= 0.99;
|
||||
body.vy *= 0.99;
|
||||
|
||||
const rect = body.el.getBoundingClientRect();
|
||||
|
||||
// Floor Collision
|
||||
if (body.y + rect.height > floorY) {
|
||||
body.y = floorY - rect.height;
|
||||
if (body.y + body.height > floorY) {
|
||||
body.y = floorY - body.height;
|
||||
body.vy *= bounce;
|
||||
body.vx *= 0.9; // Ground friction
|
||||
body.vx *= 0.9;
|
||||
}
|
||||
|
||||
// Render Step
|
||||
body.el.style.position = "fixed";
|
||||
body.el.style.left = "0px";
|
||||
body.el.style.top = "0px";
|
||||
body.el.style.transform = `translate(${body.x}px, ${body.y}px)`;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user