How PlayerAnimation works and how to extend it
masterThe PlayerAnimation class is an abstract base class used to control player movements and idle states. It manages animation properties like speed, paused, and progress.
To create a custom animation, you can either:
- Extend
PlayerAnimation: Implement theanimate(player: PlayerObject, delta: number)method to define custom movement logic. - Use
FunctionAnimation: A convenience class that allows you to create an animation by passing a simple function that receives theplayerandprogress.
Animations are updated via the update(player: PlayerObject, deltaTime: number) method, which scales the deltaTime by the animation's speed and increments the progress.
// Using FunctionAnimation for a simple rotation
const rotationAnim = new FunctionAnimation((player, progress) => {
player.rotation.y = progress;
});