Sign in to follow this  
Santiago

Can't play animations on group

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
                }
            });
        }

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.