@modoki/engine / index / CharacterAnimator2D
Variable: CharacterAnimator2D
constCharacterAnimator2D:Trait<{flip:boolean;idleClip:string;jumpClip:string;moveThreshold:number;walkClip:string; }>
CharacterAnimator2D — the connective "attribute" that turns a 2D platformer character into an animated one: it maps a sibling CharacterController2D's motion state onto a sibling SpriteAnimator's active clip, and mirrors the sprite by facing.
Put it on the SAME entity as the Renderable2D + SpriteAnimator + CharacterController2D. Each frame characterAnimationSystem picks the clip:
- airborne (
!grounded) →jumpClip - grounded & |moveX| > threshold →
walkClip - grounded & (near-)still →
idleClipand, whenflipis on, setsTransform.sx's sign from the move direction (the base sheet faces right; moving left flips it). Switching clips restarts the new track from frame 0.
Determinism: reads only trait fields (no DOM / wall-clock), so it's safe under the harness and the determinism guard. Facing writes Transform.sx, which the 2D renderer multiplies into the sprite's scale while the physics collider ignores it (unscaled world units).