Jump to content

Can't play animations on group


Santiago
 Share

Recommended Posts

I can't get on working some animations to a group of enemies, and I can't solve it. I could do it with a spritesheet, but with an atlas seems not working

here's the code:

moveEnemies: function () {
            
        for (var i = 0; i < this.enemies.length; i++) {
            
        this.enemyChild = this.enemies.children[i];
            
            if (this.enemyChild.body.touching.down) {

                if (this.enemyChild.body.x < (this.player.body.x - 40)) {

                    this.enemyChild.body.velocity.x = 100;
                    this.enemyChild.scale.x = 1;
                    this.enemies.callAll('animations.add', 'animations', 'enemigoAnim',Phaser.Animation.generateFrameNames('caminaE_', 1, 4), 10, true);
                    this.enemies.callAll('animations.play', 'animations', 'caminaE_');


                } else if (this.enemyChild.body.x > (this.player.body.x + 40)) {

                   this.enemyChild.body.velocity.x = -100;
                   this.enemyChild.scale.x = -1;
                   this.enemies.callAll('animations.add', 'animations', 'enemigoAnim',Phaser.Animation.generateFrameNames('caminaE_', 1, 4), 10, true);
                   this.enemies.callAll('animations.play', 'animations', 'caminaE_');

                } else {

                    this.enemies.children[i].body.velocity.x = 0;
                    //this.enemies.callAll('animations.stop', 'animations', 'enemigoAnim')
                }
            }
        }
    },

    ataquePlayer: function () {

        

        if (this.Q.justDown && game.physics.arcade.overlap(this.player, this.enemies)) {

            //this.player.animations.play('ataque')
            this.counter++

            game.physics.arcade.overlap(this.player, this.enemies, function (player, enemy) {

                enemy.damage(25);

                enemy.body.drag.x = 150


                if (player.scale.x == 1) {
                    enemy.body.velocity.x = 130
                    enemy.body.velocity.y = -300

                } else {
                    enemy.body.velocity.x = -130
                    enemy.body.velocity.y = -300
                }
            });
        }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...