Таблица спрайтов createjs не анимируется

Некоторое время я пытался сделать перемещение таблицы спрайтов и пробовал различные способы, описанные в документации на станки. Я до сих пор не могу заставить эту чертову штуку работать. Так что я надеялся, что кто-то из вас сможет взглянуть на это.

Я использую таблицу спрайтов 160x40, где 1 спрайт 40x40.

Вот моя вражеская функция, которая должна иметь анимацию: (строка 25-я — это создание. В функции перемещения — это gotoandplay)

var enemyWidth = 40;
var enemyHeight = 40;
function Enemy(number) {
    this.number = number;
    this.id = 'enemy';
    var randomStartLoc = new locationOutsidePlayfield();

    enemyLoc = new locationOutsidePlayfield();
    this.x = randomStartLoc.x;
    this.y = randomStartLoc.y;

    this.health = 100;

    //The damage a collision the enemy with a player does
    this.damage = 30;

    var target = new Target(this.x, this.y);
    this.velX = target.velX;
    this.velY = target.velY;

    this.hitScore = 25;
    this.killScore = this.hitScore*2;


    var spriteSheet = new createjs.SpriteSheet({
        images: ["resources/sprites/enemy_spritesheet.png"], 
        frames: {width:40, height:40},
        animations: {
            walk: [0, 3]
        }
    });

    this.sprite = new createjs.BitmapAnimation(spriteSheet);
    this.sprite.currentFrame = 0;

    this.sprite = new createjs.BitmapAnimation(spriteSheet);

    this.sprite.x = this.x;
    this.sprite.y = this.y;
    this.sprite.width = enemyWidth;
    this.sprite.height = enemyHeight;


    this.collide = function(arrayIndex, bullet) {
        if (bullet) {
            this.health -= player.damage;
        }

        if (this.health <= 0) {
            //Generate a number between 0 and 10. If it's 1(10% chance) a powerup will be made on the spot of the death.
            var percentage = Math.round(getRandomNumber(0, 10));

            //If the percentage is one and there are no powerUps on the stage it's okay to add a powerup.
            if (percentage < 6 && powerUp.length == 0) {
                var pwrp = new Powerup(this.x, this.y);
                powerUp.push(pwrp);
                if (!powerUpLayer) {
                    powerUpLayer = new createjs.Container();
                    stage.addChild(powerUpLayer);
                }
            }

            //Increase the score
            score.increaseScore(this.killScore);

            //Delete the object
            delete this;

            //Remove the sprite
            enemyLayer.removeChild(this.sprite);

            //Remove the enemy and the bullets from their array
            enemies.splice(arrayIndex, 1);
            for (var i in this.bullets) {
                ammoLayer.removeChild(this.bullets[i].sprite);
                delete this.bullets[i];
            }
            this.bullets = [];
        } else {
            //If the enemy didnt die, update the score with the hit score.
            score.increaseScore(this.hitScore);
        }

        countEnemies();
    }

    this.draw = function() {
        //enemyLayer.draw();
    }

    this.move = function() {
        this.sprite.gotoAndPlay("walk");  
        //Set a boolean that will check later on if the enemy should change direction. Therefore getting a new X an Y.
        var directionChange = false;
        this.x += this.velX;
        this.y += this.velY;

        this.sprite.x = this.x;
        this.sprite.y = this.y;

        if (this.y <= -150) {
            directionChange = true;
        }

        if (this.y >= (stage.canvas.height-this.sprite.height)+150) {
            directionChange = true;
        }

        if (this.x <= -150) {
            directionChange = true;
        }

        if (this.x >= (stage.canvas.width-this.sprite.width)+150) {
            directionChange = true;
        }

        if (directionChange == true) {
            var target = new Target(this.x, this.y);
            this.velX = target.velX;
            this.velY = target.velY;
        }
    }

    this.flickr = function() {
        this.sprite.alpha = 0.5;
        var enem = this.sprite;
        setTimeout(function() {
            enem.alpha = 1;
        }, 100);
    }

    this.bullets = [];
} 

По запросу функция создания врага. (p.s. этап обновляется в тикере, который работает нормально)

var enemies = [];
var newEnemiesAmount;
var oldEnemiesAmount;
function createEnemies(amount) {
    oldEnemiesAmount = (amount > 0) ? amount : oldEnemiesAmount;
    newEnemiesAmount = amount+(Math.floor(oldEnemiesAmount)/5)

    //Create a layer to spawn the enemies on
    enemyLayer = new createjs.Container();

    //Loop through the amount wanted.
    for (var i = 0; i < newEnemiesAmount; i++) {
        enemy = new Enemy(i);
        createEnemyBullet(enemy);
        //push the object in an array and add it to the newly made layer
        enemies.push(enemy);
        enemyLayer.addChild(enemy.sprite);
    }

    stage.addChild(enemyLayer);
}

person CaptainCarl    schedule 03.04.2013    source источник
comment
Вы вообще видите отображение таблицы спрайтов? Вы не показываете код своего приложения, в котором создается враг, добавляется спрайт на сцену или обновляется сцена — можете ли вы показать какой-то контекст?   -  person Lanny    schedule 04.04.2013
comment
да. Я вижу первое изображение в последовательности. Проект довольно масштабный, поэтому, честно говоря, скрипка не вариант. Я как бы надеялся, что просто сделал глупую ошибку при создании таблицы спрайтов. Помимо. Стадия обновляется в тикере, так что это не должно быть проблемой. Я добавлю вражеское творение в свой пост. Так что к тому времени, когда вы читаете это, он должен быть там ;-)   -  person CaptainCarl    schedule 04.04.2013
comment
Я не вижу ничего выскакивающего — возможно, я изолирую материал SpriteSheet от шипа, чтобы убедиться, что он работает — я подозреваю, что есть что-то еще, что влияет на это извне.   -  person Lanny    schedule 04.04.2013
comment
Я бы поддержал предложение изолировать проблему. Просто создайте тестовый спрайт-лист прямо на этапе игры MAIN и заставьте его играть. Если это не работает, попробуйте создать тестовую таблицу спрайтов JSON с ZOE из набора PNG, чтобы перепроверить, что это не имеет отношения к конфигурации таблицы спрайтов.   -  person sbat    schedule 10.04.2013
comment
Я попробую. Спасибо!   -  person CaptainCarl    schedule 11.04.2013
comment
Можете ли вы подтвердить, что gotoAndPlay работает? Возможно, отладьте эту строку и убедитесь, что она вызывается.   -  person Lanny    schedule 15.04.2013
comment
Мне жаль Лэнни. Сейчас я завален другой работой. Я буду держать вас в курсе!   -  person CaptainCarl    schedule 16.04.2013


Ответы (1)


Попробуйте указать количество кадров в таблице спрайтов при создании таблицы спрайтов.

var spriteSheet = new createjs.SpriteSheet({
    images: ["resources/sprites/enemy_spritesheet.png"], 
    frames: {width:40, height:40, count: 4},
    animations: {
        walk: [0, 3]
    }
});
person Anish Patel    schedule 14.04.2013