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

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
});
}
});
});
}