Flaxis / slick-ui

Lightweight Phaser UI plugin
http://slick-ui.com/
190 stars 25 forks source link

Update button/element text and/or destroy panel? #16

Closed praine closed 7 years ago

praine commented 7 years ago

Hi there, thanks for this useful plugin. I'm trying to use it to dynamically generate multiple choice questions (see image). I either need to destroy the panel and create a new one each time a new question prompt occurs, or update the text on the buttons/elements.

I can't find anything in the documentation to destroy() or kill() panels once they have been created, nor any way to dynamically update button/element text.

Any help gratefully received.

Best, Paul screen shot 2017-01-31 at 3 29 05 pm

Flaxis commented 7 years ago

There isn't really any documentation for changing text. There should be a multi paged documentation at some point.

Anyway, you can change a TextElement's value like so:

yourTextElement.text.text = 'My updated text.';

I would advise against destroying and re-creating panels, since it tends to go against object oriented design principles. A panel / button / text / anything should have one purpose and one purpose only. If you're using the same panel for multiple views, you might be doing something wrong.

praine commented 7 years ago

Thanks for your prompt reply, Flaxis. I'll try updating the text with the method you provided.

Flaxis commented 7 years ago

I just noticed as well, that you should be able to use textElement.value = 'foo';, since I apparently made a setter for it :) Anyway, is this issue solved?

praine commented 7 years ago

Thanks for that! Closing the issue now..