Jump to content

Cannot read property 'y' of undefined


lucasg07
 Share

Recommended Posts

Hi,

I'm really new to Phaser, I'm trying to get the y value of an element from a sprite in an array. But I'm getting the error cannot read property 'y' of undefined. What am I doing wrong? Thanks for the help.

this.platforms.children.entries.forEach(elem => { //this.platform is a staticgroup with 10 sprites
      console.log(elem); //returns arcadesprite
      this.platformYMin = Math.min(this.platformYMin, elem.y);
      
      if (elem.y > this.camera.y + this.game.height) {
        elem.kill();
        this.platforms.create(
          Phaser.Math.Between(50, 450),
          this.platformYMin - 100,
          'tile'
        );
      }
    });
Link to comment
Share on other sites

You might need to post more complete code; not sure what .entries is referencing.  Is this.platforms a Phaser GameObject Group?  If so, you should probably use the getChildren method: this.platforms.getChildren().forEach().

What does elem log out?

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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