# nodesnim/nodes2d/animated_sprite

Dark Mode

Search:
Group by:

It provides display animated sprites.

# Imports

../thirdparty/opengl, ../core/vector2, ../core/rect2, ../core/anchor, ../core/input, ../core/enums, ../core/image, ../core/color, ../core/animation, ../nodes/node, node2d

# Types

    AnimatedSpriteObj = object of Node2DObj
      reversed*, paused*: bool
      filter*: ColorRef
      animation*: string
      animations*: AnimationArray[GlTextureObj]

    AnimatedSpriteRef = ref AnimatedSpriteObj

# Procs

    proc AnimatedSprite(name: string = "AnimatedSprite"): AnimatedSpriteRef {...}{.raises: [],
        tags: [].}

  Creates a new AnimatedSprite.

  Arguments:

  - `name` is a node name.

  Examples:

      var node = AnimatedSprite("AnimatedSprite")

# Methods

    method draw(self: AnimatedSpriteRef; w, h: GLfloat) {...}{.raises: [GLerror], tags: [].}

  this method uses in the `window.nim`.

    method duplicate(self: AnimatedSpriteRef): AnimatedSpriteRef {...}{.base, raises: [],
        tags: [].}

  Duplicates AnimatedSprite object and create a new AnimatedSprite.

    method getGlobalMousePosition(self: AnimatedSpriteRef): Vector2Ref {...}{.inline,
        raises: [], tags: [].}

  Returns mouse position.

    method addAnimation(self: AnimatedSpriteRef; name: string; speed: float = 2.0'f32) {...}{.
        base, raises: [], tags: [].}

  Adds a new animation to the AnimatedSprite animations.

  Arguments:

  - `name` is an animation name.
  - `speed` is an animation speed.

    method addFrame(self: AnimatedSpriteRef; name: string; frame: GlTextureObj) {...}{.base,
        raises: [], tags: [].}

  Adds a new frame in the animation.

  Arguments:

  - `name` is an animation name.

    method removeAnimation(self: AnimatedSpriteRef; name: string) {...}{.base, raises: [],
        tags: [].}

  Deletes animation from the AnimatedSprite animations. If `name` is a current animation name, then animation will not delete.

  Arguments:

  - `name` is an animation name.

    method pause(self: AnimatedSpriteRef) {...}{.base, raises: [], tags: [].}

  Stops animation.

    method play(self: AnimatedSpriteRef; name: string = ""; backward: bool = false) {...}{.base,
        raises: [], tags: [].}

  Plays animation.

  Arguments:

  - `name` is an animation name. if it is "" than plays current animation.
  - if `backward` is true then plays animation in reverse order.

    method resume(self: AnimatedSpriteRef) {...}{.base, raises: [], tags: [].}

  Resumes animation.

    method setSpeed(self: AnimatedSpriteRef; name: string = ""; speed: float = 2.0'f32) {...}{.base,
        raises: [], tags: [].}

  Changes animation speed. If `name` is "" then changes the speed of the current animation.

  Arguments:

  - `name` is an animation name.
  - `speed` is a new speed.