Rework unit animations as frame-by-frame sheets
This commit is contained in:
@@ -2,10 +2,12 @@ import Phaser from 'phaser';
|
||||
|
||||
export type UnitDirection = 'south' | 'east' | 'north' | 'west';
|
||||
|
||||
const unitWalkFrameCount = 4;
|
||||
const unitIdleFrameCount = 8;
|
||||
const unitWalkFrameCount = 8;
|
||||
export const unitBaseFramesPerDirection = unitIdleFrameCount + unitWalkFrameCount;
|
||||
export const unitSheetFrameSize = 313;
|
||||
const unitWalkFrameRate = 8;
|
||||
const unitIdleFrameRate = 3;
|
||||
const unitWalkFrameRate = 10;
|
||||
const unitIdleFrameRate = 5;
|
||||
const unitSheetRows: Record<UnitDirection, number> = {
|
||||
south: 0,
|
||||
east: 1,
|
||||
@@ -95,11 +97,11 @@ export function ensureUnitAnimations(scene: Phaser.Scene, keys: Iterable<string>
|
||||
(['south', 'east', 'north', 'west'] as UnitDirection[]).forEach((direction) => {
|
||||
const frames = Array.from({ length: unitWalkFrameCount }, (_, frameIndex) => ({
|
||||
key,
|
||||
frame: unitSheetRows[direction] * unitWalkFrameCount + frameIndex
|
||||
frame: unitSheetRows[direction] * unitBaseFramesPerDirection + unitIdleFrameCount + frameIndex
|
||||
}));
|
||||
const idleFrames = [0, 1, 0, 3].map((frameIndex) => ({
|
||||
const idleFrames = Array.from({ length: unitIdleFrameCount }, (_, frameIndex) => ({
|
||||
key,
|
||||
frame: unitSheetRows[direction] * unitWalkFrameCount + frameIndex
|
||||
frame: unitSheetRows[direction] * unitBaseFramesPerDirection + frameIndex
|
||||
}));
|
||||
const walkAnimationKey = `${key}-walk-${direction}`;
|
||||
const idleAnimationKey = `${key}-idle-${direction}`;
|
||||
|
||||
Reference in New Issue
Block a user