Set Phaser.World as parent for sprite


#1

I’m trying to impelemt item pick up and drop in my game.
For picking up I’m doind this:

player.addChild(goldenKey);
goldenKey.x = 0;
goldenKey.y = 0;

Question is how to ‘drop’ the item?
When I do

player.removeChild(goldenKey);
goldenKey.reset(goldenKey.realX, goldenKey.realY);

item disappers somewhere.
I think that I have to set Phaser.World as parent again to make it visible.


#2

Hi @microspace
I think it’s becaue of positions, what is realX and realY values actually.

As far as i know, you could just do:

this.world.add(player.goldenKey)
or
game.add.existing(player.goldenKey)

After doing these, you could set to position of goldenKey


#3

Hi @hcakar! This was really really helpful and incredibly fast answer! You are awesome!