lucasg07 Posted November 18, 2018 Share Posted November 18, 2018 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 More sharing options...
prob Posted November 18, 2018 Share Posted November 18, 2018 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 More sharing options...
rich Posted November 18, 2018 Share Posted November 18, 2018 This is almost certainly just a scope error, as `this` carries a different meaning within a function, like your forEach is using. Link to comment Share on other sites More sharing options...
Gustavo Flores Posted November 19, 2018 Share Posted November 19, 2018 Maybe you need use "this.cameras.main.y" Link to comment Share on other sites More sharing options...
lucasg07 Posted November 20, 2018 Author Share Posted November 20, 2018 16 hours ago, Gustavo Flores said: Maybe you need use "this.cameras.main.y" This was indeed correct, but this returned 0 all the time. I then used this.camera.main.scrollY, this did work. Link to comment Share on other sites More sharing options...
Recommended Posts