Search code examples
javascriptcanvaseaseljscreatejs

EaselJS: Cannot get BitmapAnimation to display on stage


I'm trying to draw an animated bitmap on my stage but I can't seem to get it working. I can verify the animation is added to the stage in the console but it's not displaying.

HTML:

<canvas id="canvas" width="300" height="300"></canvas>

JavaScript:

var canvas = document.getElementById('canvas'),
    stage = new createjs.Stage(canvas),
    chopperImg = document.createElement('img'),
    spriteSheet,
    animation;

chopperImg.addEventListener('load', function ( e ) {

    spriteSheet = new createjs.SpriteSheet({
        images: [ chopperImg ],
        frames: { width: 64, height: 75, count: 10 },
        animations: {
            idle: [ 0, 9, 'idle', 4 ]
        }
    });

    animation = new createjs.BitmapAnimation(spriteSheet);
    animation.gotoAndPlay('idle');

    stage.addChild(animation);

    createjs.Ticker.setFPS(30);
    createjs.Ticker.addListener(stage);
});

chopperImg.src = 'http://dutchnoobz.nl/chopper.gif';

I've made a JSFiddle demonstrating my problem here: http://jsfiddle.net/WWpVX/1/


Solution

  • Your GIF has a height of only 73px, your frame-dimensions cannot exceed the image-dimensions, I've updated your fiddle, it works here: http://jsfiddle.net/WWpVX/2/

    frames: { width: 64, height: 73, count: 10 }