Draxy Posted July 4, 2017 Share Posted July 4, 2017 I have a player in a group like this: this.players = this.game.add.physicsGroup(); blue_player = this.players.create(0, this.world.height - 490, 'blue_player'); this.players.setAll('body.bounce.y', 0.2); this.players.setAll('body.gravity.y', 1000); this.players.setAll('collideWorldBounds', true); blue_player.animations.add('idle',[0,1,2],2.1,true); this.players.callAll('animations.play', 'animations', 'idle'); And I add a function to my game prototype that is called by my update function: blue_controls: function () { if (blue_keyMap.jump.isDown) { console.log("blue is going up in the world"); this.players.blue_player.body.velocity.y = 2000; } }, And get: TypeError: Cannot read property 'body' of undefined The error is with this line: this.players.blue_player.body.velocity.y = 2000; I have tried just this.blue_player.body.velocity but get blue_player undefined, and others. I've ran out of things to try that I can think of. I know I'm not referencing the object correctly, but I'm currently putting in the milage to learn object Inheritance and prototypes - and using this game I'm making as practice. I'm just a little stuck, help a noob out? Link to comment Share on other sites More sharing options...
squilibob Posted July 4, 2017 Share Posted July 4, 2017 If you're not going to set a variable to reference the player like using this.blue_player instead of blue_player then you'll have to work out which child it is in the group like this.players.children[0].body.velocity.y Link to comment Share on other sites More sharing options...
Draxy Posted July 4, 2017 Author Share Posted July 4, 2017 I never knew this was a thing, and it works! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts