Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AnimatedSprite

A sprite that holds an animation based on a sprite sheet. Needs to be updated on each frame for the animation to play.

Hierarchy

Index

Constructors

  • Parameters

    • image: CanvasImageSource
    • frames: Rect[]

      a set of rectangle delimiting the part of the sprite sheet for each frame.

    • Optional destRects: Rect[]

      a set of return delimiting the zone where the frame must be drawn. The position of the destRects is overwritten as the sprite is moved around.

    Returns AnimatedSprite

Properties

anchor: AnchorType
animations: Map<string, SpriteAnimation>
currentAnimation?: SpriteAnimation
currentFrame: number = 0
destRect: Rect
destRects: Rect[]
flipX: boolean = false
flipY: boolean = false
frames: Rect[]
image: CanvasImageSource
playing: boolean = false
rotation: number = 0
scale: number = 1
sourceRect: Rect
time: number = 0

Accessors

  • Position of the sprite defined by anchor Do not set components of the position directly, it will not update it properly. Instead, assign to the property:

    example
    const p = sprite.pos
    p.x += 0.5;
    sprite.pos = p;

    Returns Vec2

  • Position of the sprite defined by anchor Do not set components of the position directly, it will not update it properly. Instead, assign to the property:

    example
    const p = sprite.pos
    p.x += 0.5;
    sprite.pos = p;

    Parameters

    Returns void

  • The rect bounding the sprite, taking scaling into account.

    Returns Rect

Methods

  • addAnimation(animationName: string, frameStart: number, frameEnd: number, delay: number, loop?: boolean): AnimatedSprite
  • add animation

    Parameters

    • animationName: string

      name of animation

    • frameStart: number

      frame to begin from

    • frameEnd: number

      frame to end at

    • delay: number

      delay between each frame

    • Optional loop: boolean

    Returns AnimatedSprite

  • play animation

    Parameters

    • animationName: string

      name of animation to play

    Returns AnimatedSprite

  • stop the sprite animation

    Returns AnimatedSprite

  • Called on each frame to update sprite states

    Parameters

    • dt: number

      delta time

    Returns AnimatedSprite

Generated using TypeDoc