jetlag2d
    Preparing search index...

    Class AnimatedSprite

    AnimatedSprite describes any object whose visual representation is an animation. There can be many types of animations. The "IDLE_E" (right-facing) animation is the default. AnimatedSprite can be notified when an Entity's state changes, so that it can switch to the animation associated with the new state.

    Implements

    Index

    The animation sequences to use (they correspond to different AnimationStates)

    height: number

    Height of the animation

    offset: JLOffset

    An offset between the AnimatedSprite's center and the RigidBody's center

    onFrameChange?: (index: number, state: AnimationState) => void

    Optional callback that runs whenever the active frame changes. Receives the new frame's 0-based index within the current AnimationSequence, and the AnimationState that sequence corresponds to.

    stateSelector: (_oldState: ActorState, newState: ActorState) => AnimationState = AnimatedSprite.overheadAnimationTransitions

    A function for selecting what animation state to move to when the attached actor's state changes. Defaults to the version for overhead-style games.

    Type Declaration

      • (_oldState: ActorState, newState: ActorState): AnimationState
      • Figure out what AnimationState to use, given an ActorState. This version is designed for top-down style games, where the camera seems to be overhead.

        NB: This is the default version, but there's no guarantee that it is very good. It is used via stateSelector, which can be overridden. Or you could chose to modify it for your game.

        Parameters

        • _oldState: ActorState

          The state that the actor was in

        • newState: ActorState

          The details of the new state the actor is moving to

        Returns AnimationState

    width: number

    Width of the animation

    z: -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4

    Z index of the image

    • Render the animated image's current cell when it does not have a rigidBody. This is only used for Parallax

      Parameters

      • anchor: { cx: number; cy: number }

        The center x/y at which to draw the image

      • camera: CameraService

        The camera for the current stage

      • foreground: boolean

        Should this go in the foreground (true) or background (false)

      Returns void

    • Skip to the indexth cell of the animation, and move forward within it by elapsed milliseconds. Does nothing (and prints no error) if the index is out of bounds.

      Parameters

      • index: number

        The 0-based index of the cell of the animation within the current AnimationSequence

      • elapsed: number

        Act as if this many milliseconds within the new cell have passed.

      Returns void

    • Figure out what AnimationState to use, given an ActorState. This version is designed for top-down style games, where the camera seems to be overhead.

      NB: This is the default version, but there's no guarantee that it is very good. It is used via stateSelector, which can be overridden. Or you could chose to modify it for your game.

      Parameters

      • _oldState: ActorState

        The state that the actor was in

      • newState: ActorState

        The details of the new state the actor is moving to

      Returns AnimationState

    • Figure out what AnimationState to use, given an ActorState. This version is designed for side-view style games, where the camera seems to be at ground level.

      NB: As in overheadAnimationTransitions, this may not be good for your game, so you can always override it or rewrite it.

      Parameters

      • oldState: ActorState

        The state that the actor was in

      • newState: ActorState

        The details of the new state the actor is moving to

      Returns AnimationState

      The new AnimationState for the actor