Jump to content

Parent child GameObjects best practice


Doug
 Share

Recommended Posts

Hi

I'm trying to create a scene where randomly generated balloons move across the screen with toys hanging from them.  When the user clicks the balloon the toy will drop and either hit or miss a basket.

I would like to use a tween on the y position of each balloon so that they move up and down as well.

I would like to use a tween on the toy so that it swings a bit (less important).

I am thinking of setting up an array to push the balloon objects into so that I can push and pop as they are generated and destroyed.  What is the best way to set up the parent > child relationship for the balloon and toys though please?

Should I create a Phaser.GameObjects.Group() and create() the balloon and toy within that group and then push that group into my array?

Or should I create each balloon and toy as a Phaser.GameObjects.Sprite and set a parent > child relationship somehow (I think you could use addChild() in Phaser 2?)?

Or should I be using physics bodies and linking the toy to the balloon somehow, and then releasing that link to drop the toy when the balloon is clicked?

Thanks!

By the way, I don't know if it's helpful, but there is an error in http://labs.phaser.io/view.html?src=src\physics\arcade\circular body.js - "Uncaught ReferenceError: GetOverlapX is not defined".

 

game1.png

Link to comment
Share on other sites

That's an interesting question. In phaser 2, I needed something similar recently. I wanted to have a slime that has 1) a tween animation in y scale, 2) a scale fixed physics body, and 3) UI elements attached to it (action points bar, health bar). 

What I finally did is to create an empty Sprite (no texture) as a root. This root has a body for the physics. Then I added a Sprite as a child to display the slime texture with a y-scale tween, and I added a group as a child for the UI elements.

Please post your updates. I am also curious about what are the best practices and/or on how to do it with phaser 3. :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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