PixelProgrammer

How to find position of child sprite relative to world?

Recommended Posts

Hi there!

 So here's my issue. I have a player sprite which has an orb sprite attached to it as a child. 

Player = function (game, x, y, image) {

    Phaser.Sprite.call(this, game, x, y, image); //calls constructor

    this.orb = this.addChild(game.make.sprite(0, 0, 'orb'));



    game.add.existing(this);
};

/*--------------------------------------------------------*/
Player.prototype = Object.create(Phaser.Sprite.prototype);
Player.prototype.constructor = Player;
/*--------------------------------------------------------*/

I want to reference the x and y positions of the orb so that I can shoot bullets out of it. 

BUT, if I console.log(this.orb.x) or the y position, the value that is returned is 0.

What do I do so that I can get the x and y positions of the orb, relative to the game world and not the parent sprite??

orbAndPlayer.png.66c17b7617d37769536646be7924c6cd.png 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.