1.1.2 • Published 5 years ago

@curiousmedia/canvas-animator v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

CanvasAnimator

Generate AnimateCC spritesheets and display them in a canvas element

How to generate a Sprite Sheet from Animate CC for use with Canvas Animator:

Right click on the symbol you want to export and choose Generate Sprite Sheet...

Choose from available export options.

Verify Data Format is set to JSON-Array and click Export

Usage:

Load and Parse the JSON-Array data that was exported from AnimateCC

Make a new instance of CanvasAnimator:

let animation = new CanvasAnimator(
    document.querySelector('canvas'),
    jsonData,
    60,
    false
);

Event Listeners

    animation.on('complete', function(event){
        console.log(event.frame);
    });

new CanvasAnimator(element, data, framerate, loop)

Constructor

ParamTypeDefaultDescription
elementCanvasRequired: The canvas element to display the animation on
dataObjectRequired: The JSON Array data from Animate CC
framerateNumber24Optional: Framerate to run the animation at Default: 24
loopBooltrueOptional: Does the animation loop or play once and stop Default: true

canvasAnimator.framerate - GETTER

Get the framerate our animation is playing at

canvasAnimator.framerate - SETTER

Set the framerate to play the animation at

ParamTypeDescription
rateNumberFPS for the animation to run at

canvasAnimator.loop - GETTER

Get the loop property

canvasAnimator.loop - SETTER

Set the loop property to be true or false

ParamType
boolBool

canvasAnimator.handleImageLoaded()

Image onload handler called when the image is done loading

canvasAnimator.drawFrame(dataFrame)

Draw the image based on data from the JSON data array

ParamType
dataFrameObject

canvasAnimator.play()

Play the animation

canvasAnimator.pause()

Pause the animation

canvasAnimator.gotoAndPlay(frame)

Go to the specific frame number

ParamTypeDescription
frameNumberframe number to go to

canvasAnimator.render()

Request Animation Frame

canvasAnimator.on(type, listener, useCapture)

Shortcut to add event listeners for the canvas element

ParamTypeDefaultDescription
typeStringRequired. A String that specifies the name of the event.
listenerfunctionRequired. Specifies the function to run when the event occurs.
useCaptureBoolfalseOptional. A Boolean value that specifies whether the event should be executed in the capturing or in the bubbling phase.

canvasAnimator.off(type, listener, useCapture)

Shortcut to remove event listeners for the canvas element

ParamTypeDefaultDescription
typeStringRequired. A String that specifies the name of the event.
listenerfunctionRequired. Specifies the function to run when the event occurs.
useCaptureBoolfalseOptional. A Boolean value that specifies whether the event should be executed in the capturing or in the bubbling phase.

Events

Start

Called when the image is loaded and the RequestAnimationFrame begins

Change

Called when a new frame in the animation is rendered

Complete

Called when the last frame of the animation has played and the animation is returning to Frame 0 unless loop = false

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago