Jump to content

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

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...