cheshirepuss42 Posted February 17, 2014 Share Posted February 17, 2014 I'm making a game where you make words by clicking letters. Eventually these letters will be images, but for now I'm trying to make something like a button: a clickable square with some text over it. I was familiar with how to do this in AS3, but now I don't have addchild at my disposal to build a combination of sprites.I thought that maybe I had to use groups to combine the button and the text, but this would mean that for every lettersquare I make a new group, which seems wrong.In examples I only see groups being used to handle multiple sprites, but the real use of them is unclear to me.So i guess I have two questions: - How do I make a button with dynamic text? - When and how do I use groups? Link to comment Share on other sites More sharing options...
rich Posted February 17, 2014 Share Posted February 17, 2014 Think of a Group as being a DisplayObjectContainer (because that's exactly what it is!) - use them often and frequently, just as you would in AS3 really. Currently you can't do a button with dynamic text, sorry. You could create your own object that combines a Button and a Text object together, but making the button resize to fit the text would be a bit of a challenge (not impossible by any means, just a bit of work). Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted February 17, 2014 Author Share Posted February 17, 2014 So if i would make a seperate sprite-like class for a creature with a healthbar and particles and things it would best be derived from a Group?And the healthbar would also be a Group?And to track them I would just use the references given by this.game.add.existing(creature)?Would I have to call this.game.add for the healthbar too, or would this be added by adding the parent (creature)? Link to comment Share on other sites More sharing options...
rich Posted February 17, 2014 Share Posted February 17, 2014 It really depends - for example if I was doing this in Flash I wouldn't bundle everything inside a single DisplayObject, I'd split them out a bit - but technically though there's no reason why you can't do it the way you described. Also worth mentioning that Sprites extend DisplayObjectContainer, so can have children too. This is cleaner under Phaser 1.2, but should still work under 1.1. Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted February 17, 2014 Author Share Posted February 17, 2014 How would this work?I am using typescript which i assume might not be up to date, but I also dont see .add with the sprite class in the api (http://gametest.mobi/phaser/docs/Phaser.Sprite.html). Btw, thanks for your efforts, Phaser seems like a great shore to land from Flash-country (especially as I have been using Flashpunk, which is related to Flixel i think). Link to comment Share on other sites More sharing options...
Recommended Posts