Doug Posted February 17, 2018 Share Posted February 17, 2018 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". Link to comment Share on other sites More sharing options...
Nodragem Posted February 17, 2018 Share Posted February 17, 2018 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 More sharing options...
Doug Posted February 21, 2018 Author Share Posted February 21, 2018 Thanks @Nodragem Please see https://github.com/photonstorm/phaser/issues/3246 as there is discussion on this issue there, and also a Ziao has also posted a solution. PBMCube 1 Link to comment Share on other sites More sharing options...
Recommended Posts