Animation options
Animation control interface
// Basic usage
const { currentState, currentFrame, update, transitionTo } = usePlayerAnimation({
events: {
onAnimationStart: (state) => console.log(`Started ${state}`),
onAnimationComplete: (state) => console.log(`Completed ${state}`),
onFrame: (frame, state) => {
if (state === "attack" && frame === 6) {
// Execute attack at midpoint
executeAttack();
}
}
}
});
// In useFrame callback
useFrame((state, delta) => {
const result = update(delta);
// Update visuals based on result.state and result.frame
});
// Trigger animations
const handleAttackInput = () => {
transitionTo("attack");
};
const handleMovement = (isMoving: boolean) => {
transitionTo(isMoving ? "walk" : "idle");
};
React hook for player animation state management
Provides frame-accurate animation control with priority system and event callbacks. Integrates seamlessly with useFrame for 60fps updates.