Search code examples
javascriptspritecreatejssprite-sheet

TypeError: createjs.Sprite is not a constructor


I am trying to make animation with an image file that is a SpriteSheet and when I run the code I get the error that is displayed in the title.

My code looks like this:

 Game.Hero = function (myX, myY) {
'use strict';
 var data = new createjs.SpriteSheet({
    "images":[Game.imgResSrcs["hero"]],
    "frames" : {
        "regX": myX, 
        "height": 60, 
        "regY": myY, 
        "width": 60
    },

    animations: {
        move: {
            frames: 
            [0,1,2,3,4,5,4,3,2,1],
            speed : 0.04
        },
        run: {
            frames: [1,2,3],
            speed:0.04
        }
    }
});
var startX = myX,
startY = myY,
speed = 2,
my = new createjs.Sprite(data, "move");

my.moveTo = function (newX, newY, tween) {
    var newXpx, newYpx;
    my.posX = newX;
    my.posY = newY;

    Game.stage.update();
};

I'm guessing it has something to do with this line: my = new createjs.Sprite(data, "move");

Am I forgetting something here or what could possibly be generating the error ?


Solution

  • You are using:

    my = new createjs.Sprite(data, "move");
    

    and the error is: TypeError: createjs.Sprite is not a constructor

    So, it seems you have to change that line to:

    my = createjs.Sprite(data, "move");
    

    But that is most probably not the correct because all example uses new createjs.Sprite().

    Possible reason could be that you have no included Sprite in minified file.