zbzzn Posted September 23, 2013 Share Posted September 23, 2013 Hi, Sorry for the n00b question. Perhaps my terminology isn't right too.I want to create a layered sprite of a tank. Layers are- Hull (image)- Turret (image)- Aiming Guide (Vector Graphic)- Health Bar (Vector Graphic) How do I do it with Phaser properly?(If possible just link me to an example or docs on how to do it). I cannot use separate sprites because when the tank turns the turret needs to turn accordingly.I am actually porting it from CreateJS so there is an example of what I am doing here:http://boriskozo.github.io/Tanks/ Thanks,Boris. Link to comment Share on other sites More sharing options...
rich Posted September 23, 2013 Share Posted September 23, 2013 You can use a Sprite, but just add the other components as children of that Sprite, so they can all turn together. Phaser uses Pixi, which basically gives you a Flash style display list. You could also use a Group, but I'd probably go for the nested Sprite approach. Link to comment Share on other sites More sharing options...
zbzzn Posted September 23, 2013 Author Share Posted September 23, 2013 Thanks, I will try that. I am not coming from Flash so I am not sure what "Flash style display list" is. I always thought this is a common scenario - layered sprites. Link to comment Share on other sites More sharing options...
zbzzn Posted September 23, 2013 Author Share Posted September 23, 2013 Can I create a Sprite without a key?new Phaser.Sprite(x,y); The code seems to support it but rendering it gives an error.Should I use some other class as the container? Link to comment Share on other sites More sharing options...
rich Posted September 23, 2013 Share Posted September 23, 2013 You can have a sprite without a key but it renders as a black square. If you just want a container that doesn't actually render itself but has lots of children that do then I would use a Group. Link to comment Share on other sites More sharing options...
zbzzn Posted September 24, 2013 Author Share Posted September 24, 2013 Thank you Rich.I will do that. Link to comment Share on other sites More sharing options...
zbzzn Posted September 24, 2013 Author Share Posted September 24, 2013 Sorry about the long thread. Why does this: create: function () { var result = new Phaser.Group(game, null, 'T72', false); result.create(0, 0, 'T72_hull'); } Draws the tank hull on screen? I didn't even add the group to anywhere?If I try to add it anyway using this.add.existing(result); there is an error. Link to comment Share on other sites More sharing options...
xerver Posted September 29, 2013 Share Posted September 29, 2013 You can use a Sprite, but just add the other components as children of that Sprite, so they can all turn together. Phaser uses Pixi, which basically gives you a Flash style display list. You could also use a Group, but I'd probably go for the nested Sprite approach.not 100% sure but I don't think sprite children are rendered. Unless it has changed recently, might be better to have a Doc with multiple sprites. I would check on that Link to comment Share on other sites More sharing options...
Vaughan Posted February 22, 2014 Share Posted February 22, 2014 Could someone give more detail on how you add children to sprites as of 1.1.5? Link to comment Share on other sites More sharing options...
Recommended Posts