fix: Stretch player sprite to match collision box height and remove levitation

This commit is contained in:
Kacper Kostka (aider) 2025-04-05 18:36:27 +02:00
parent 8e2575f6fc
commit cb62097150

View File

@ -139,12 +139,13 @@ class Player extends Entity {
// Draw the correct sprite frame // Draw the correct sprite frame
// Center the sprite on the entity position, with y-offset to align feet with collision box // Center the sprite on the entity position, with y-offset to align feet with collision box
// Stretch the sprite vertically to match the collision box height
ctx.drawImage( ctx.drawImage(
this.sprite, this.sprite,
this.currentFrame * this.frameWidth, 0, this.currentFrame * this.frameWidth, 0,
this.frameWidth, this.frameHeight, this.frameWidth, this.frameHeight,
-spriteDisplayWidth / 2, -spriteDisplayHeight / 2 - 2, // Adjusted y-offset to align with collision box -spriteDisplayWidth / 2, -spriteDisplayHeight / 2, // Remove the negative offset that caused levitation
spriteDisplayWidth, spriteDisplayHeight spriteDisplayWidth, spriteDisplayHeight * 1.2 // Stretch sprite vertically by 20% to match collision box
); );
ctx.restore(); ctx.restore();
@ -167,9 +168,9 @@ class Player extends Entity {
ctx.lineWidth = 1; ctx.lineWidth = 1;
ctx.strokeRect( ctx.strokeRect(
screenX - spriteDisplayWidth / 2, screenX - spriteDisplayWidth / 2,
screenY - spriteDisplayHeight / 2 - 2, // Match the sprite drawing offset screenY - spriteDisplayHeight / 2, // Match the updated sprite drawing position
spriteDisplayWidth, spriteDisplayWidth,
spriteDisplayHeight spriteDisplayHeight * 1.2 // Match the stretched sprite height
); );
// Draw a dot at the entity's exact position // Draw a dot at the entity's exact position