// How to display a sequence of images as an animation
// Create EaselJS Stage with canvas
var stage = new Stage($('canvas')[0]);
// Create the sprite sheet
var spritesheet = new SpriteSheet({
images: ['https://s3.amazonaws.com/dxparker/blog/zolo/dying.png'],
frames: {width: 200, height: 200},
animations: {
stand: 0, // 1 frame of the player standing
die: [1, 5, false] // 5 frame death sequence
}
});
// Create the bitmap animation from the spritesheet
// and display the standing
var player = new BitmapAnimation(spritesheet);
player.gotoAndStop('stand');
// Add click listener to trigger animation
stage.onMouseDown = function() {
player.gotoAndPlay('die');
};
// Reset player 1 second after death sequence finishes playing
player.onAnimationEnd = function() {
setTimeout(function() {
player.gotoAndStop('stand');
}, 1000);
};
// Display container on screen
stage.addChild(player);
// Set the stage refresh rate to 10 times per second
// since the animation only has 5 frames a higher
// frame rate will make the animation to short to enjoy
Ticker.setFPS(10);
// IMPORTANT: Remember to register the stage with the Ticker
// or you'll be staring at an empty canvas
Ticker.addListener(stage);
<!--
easeljs and jquery scripts have been included
using the framework and resources options of jsfiddle
-->
<canvas width="550" height="250"></canvas>
<p>Click on the canvas to trigger the animation sequence.</p>
<p>The image is reset one second after the end of the animation.</p>
canvas {
background-color: #ccd;
margin-bottom: 10px;
}
body {
font: normal normal 14px Arial, Tahoma, Helvetica, FreeSans, sans-serif;
}
External resources loaded into this fiddle: