Add level 1 background image and improve player velocity tracking

This commit is contained in:
Brian Fertig 2026-02-22 22:27:42 -07:00
parent b4b42b20d3
commit a8262f4bbf
3 changed files with 13 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 KiB

View File

@ -11,6 +11,9 @@ export default class BootScene extends Phaser.Scene {
// Key must match the name Phaser derives from the TSX source: 'platforms'
this.load.image('platforms', '../../assets/sprites/platforms.png');
// Level 1 background image
this.load.image('level1-bg', '../../assets/images/level1-background.png');
// Player spritesheet (128x256 per frame)
this.load.spritesheet('player', '../../assets/sprites/player.png', {
frameWidth: 128,

View File

@ -67,6 +67,11 @@ export default class Level1Scene extends Phaser.Scene {
}
}
// -------------------------
// Background image
// -------------------------
this.add.image(0, 0, 'level1-bg').setOrigin(0, 0).setDisplaySize(30 * 128, 20 * 128).setScrollFactor(0.3);
const map = this.make.tilemap({ key: 'level1' });
// 'platforms' = name Phaser derives from the external tileset source 'platforms.tsx'
@ -183,13 +188,15 @@ export default class Level1Scene extends Phaser.Scene {
}
update(time, delta) {
// Store velocity BEFORE player.update() so we know if player was falling
this._prevVelocityY = this._player.body.velocity.y;
this._player.update(time, delta);
this._checkButtonPress();
this._livesText.setText('Lives: ' + this._player.lives);
// Store velocity at END of frame so next frame's _checkButtonPress sees the
// pre-landing velocity. Physics zeroes velocity.y before update() is called,
// so capturing it here (post-physics, post-input) gives the correct falling speed.
this._prevVelocityY = this._player.body.velocity.y;
}
/**