Jump to content

Referencing a sprite in a group


Draxy
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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