Search code examples
javascriptarraystileeaseljscreatejs

"Array" not working within an EaselJS CreateJS Container object


I'm working on a semi-OOP game and using EaselJS as my library. To this point I've gotten it mostly working, but I'm running into a persistent and annoying problem. When I render my tiles out, the tile container is failing. It won't read the type "array" for some reason. This is my code below:

(function() {

var tile = function(array, _x, _y, spritesheet) {
  this.initialize(array, _x, _y, spritesheet);
}
tile.prototype = new createjs.Container();

tile.prototype.Container_initialize = this.initialize(array, _x, _y, spritesheet);
tile.prototype.initialize = function(array, _x, _y, spritesheet) {
    this.Container_initialize();
    this.x = _x * 120;
    this.y = _y * 120;

    this.tileArray = array; 

    this.tilesheet = spritesheet;

    for (var x = 0; x < this.tileArray.length; x++)
    {
        for (var y = 0; y < this.tileArray.length; y++)
        {
            console.log(this.tileArray[x][y]);
            var tileSprite = new createjs.Sprite(this.tilesheet, this.tileArray[x][y]);
            tileSprite.x = _x * 40 * x;
            tileSprite.y = _y * 40 * y;
        }       
    }
}

window.tile = tile;
}());

Solution

  • Remove the parameters when you define the method Container_initialize:

    tile.prototype.Container_initialize = this.initialize;