# Class: Animation

## Konva. Animation

#### new Animation(func, layers)

  Animation constructor. A stage is used to contain multiple layers and handle

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `func` | function |  | function executed on each animation frame. The function is passed a frame object, which contains timeDiff, lastTime, time, and frameRate properties. The timeDiff property is the number of milliseconds that have passed since the last animation frame. The lastTime property is time in milliseconds that elapsed from the moment the animation started to the last animation frame. The time property is the time in milliseconds that ellapsed from the moment the animation started to the current animation frame. The frameRate property is the current frame rate in frames / second. Return false from function, if you don't need to redraw layer/layers on some frames.
  `layers` | Konva.Layer | Array | <optional> | layer(s) to be redrawn on each animation frame. Can be a layer, an array of layers, or null. Not specifying a node will result in no redraw.

  Source:
    - konva-v5.2.0.js, line 6155

  ##### Example

      // move a node to the right at 50 pixels / second
      var velocity = 50;

      var anim = new Konva.Animation(function(frame) {
        var dist = velocity * (frame.timeDiff / 1000);
        node.move(dist, 0);
      }, layer);

      anim.start();

### Methods

#### addLayer(layer)

  add layer. Returns true if the layer was added, and false if it was not

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `layer` | Konva.Layer |

  Source:
    - konva-v5.2.0.js, line 6209

#### getLayers()

  get layers

  Source:
    - konva-v5.2.0.js, line 6200

#### isRunning()

  determine if animation is running or not. returns true or false

  Source:
    - konva-v5.2.0.js, line 6235

#### isRunning() → {Boolean}

  determine if animation of sprite is running or not. returns true or false

  Source:
    - konva-v5.2.0.js, line 12926

  ##### Returns:

  Type
    Boolean

#### setLayers(layers)

  set layers to be redrawn on each animation frame

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `layers` | Konva.Layer | Array | <optional> | layer(s) to be redrawn. Can be a layer, an array of layers, or null. Not specifying a node will result in no redraw.

  Source:
    - konva-v5.2.0.js, line 6176

#### start()

  start animation

  Source:
    - konva-v5.2.0.js, line 6253

#### stop()

  stop animation

  Source:
    - konva-v5.2.0.js, line 6265