Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Function not working on Phaser3 (is not a function error/is null message)


CarlosBR
 Share

Recommended Posts

this.enemies = this.physics.add.group();
        this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' });
        this.enemies.forEach((enemy) => {
            if(enemy instanceof Phaser.GameObjects.Sprite) {
                enemy.body.setBounceX(1);
            }
        });

With this code I get enemy.body is null or if I change to enemy.setBounceX(1) I get: enemy.setBounceX is not a function

The code below:
 

this.enemies = this.physics.add.group();
this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' });

this.enemies.getChildren().forEach(function(enemy) {
    enemy.body.setBounceX(1);
}, this);

also doesn't work. The error message says: this.enemies.getChildren is not a function

 

What am I doing wrong here?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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