Stabilize idle unit animations

This commit is contained in:
2026-06-22 11:39:37 +09:00
parent cbde3da8cd
commit db26a62dd4
10 changed files with 33 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 812 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@@ -1434,6 +1434,12 @@ export class BattleScene extends Phaser.Scene {
view.sprite.play(`${view.textureBase}-walk-${direction}`, true);
}
private playUnitIdle(view: UnitView, direction: UnitDirection) {
view.direction = direction;
view.sprite.setFlipX(false);
view.sprite.play(`${view.textureBase}-idle-${direction}`, true);
}
private stopUnitWalk(view: UnitView, direction: UnitDirection) {
view.direction = direction;
view.sprite.stop();
@@ -1451,7 +1457,7 @@ export class BattleScene extends Phaser.Scene {
return;
}
this.playUnitWalk(view, direction);
this.playUnitIdle(view, direction);
}
private setUnitDirectionFrame(view: UnitView, direction: UnitDirection) {

View File

@@ -21,6 +21,8 @@ type UnitDirection = 'south' | 'east' | 'north' | 'west';
const unitWalkFrameCount = 4;
const unitSheetFrameSize = 313;
const unitWalkFrameRate = 8;
const unitIdleFrameRate = 4;
const unitSheetRows: Record<UnitDirection, number> = {
south: 0,
east: 1,
@@ -82,20 +84,30 @@ export class BootScene extends Phaser.Scene {
private createUnitAnimations() {
unitSheets.forEach(({ key }) => {
(['south', 'east', 'north', 'west'] as UnitDirection[]).forEach((direction) => {
const animationKey = `${key}-walk-${direction}`;
if (this.anims.exists(animationKey)) {
return;
const frames = Array.from({ length: unitWalkFrameCount }, (_, frameIndex) => ({
key,
frame: unitSheetRows[direction] * unitWalkFrameCount + frameIndex
}));
const walkAnimationKey = `${key}-walk-${direction}`;
const idleAnimationKey = `${key}-idle-${direction}`;
if (!this.anims.exists(walkAnimationKey)) {
this.anims.create({
key: walkAnimationKey,
frames,
frameRate: unitWalkFrameRate,
repeat: -1
});
}
this.anims.create({
key: animationKey,
frames: Array.from({ length: unitWalkFrameCount }, (_, frameIndex) => ({
key,
frame: unitSheetRows[direction] * unitWalkFrameCount + frameIndex
})),
frameRate: 8,
repeat: -1
});
if (!this.anims.exists(idleAnimationKey)) {
this.anims.create({
key: idleAnimationKey,
frames,
frameRate: unitIdleFrameRate,
repeat: -1
});
}
});
});
}