daniro Posted October 8, 2015 Share Posted October 8, 2015 I'm having a issue with the group elements; I'm trying to remove them all or kill them and it won't work, it doesn't even trigger an error on console. I don't know if i'm forgetting something, but if anyone can help i will be really glad. This is my shortened code:create: function () { this.choices = game.add.group();},displayChoices: function(index) { for(var i = 0; i < 3; i++){ this.choice = this.choices.create(130, 110, 'choice'); this.choice = game.add.text(130, 140, game.global.script[index].choice); this.choice.inputEnabled = true; this.choice.events.onInputDown.add(this.choiceTest, this); }},choiceTest: function(clicked) { this.choices.callAll('kill'); //this.choices.removeAll();}I want to kill all the 'choice' created when the choiceTest() is triggered, i tried both methods but neither worked, if i am overlooking something i apologize in advance lol Regards,Danilo. Link to comment Share on other sites More sharing options...
rich Posted October 8, 2015 Share Posted October 8, 2015 this.choices.create will create a Sprite object (which you store in the variable this.choice). You then replace it with a Text object on the next line. But the original Sprite is still in the Group. Link to comment Share on other sites More sharing options...
daniro Posted October 8, 2015 Author Share Posted October 8, 2015 Oh! i said it was something i overlook lol Thanks rich!i can do the following right? besides it, it's better to enable the input in the group object(this.choices) right?this.choice = game.add.text(0, 0, "Text", {/*style*/}, otherGroup);Edit: got it from this link http://www.html5gamedevs.com/topic/2606-can-text-be-added-to-a-group-or-only-sprites/ Link to comment Share on other sites More sharing options...
rich Posted October 8, 2015 Share Posted October 8, 2015 Yes that will work. Groups themselves cannot be input enabled, so you have to enable the Text object (or a parent Sprite, depends what you need really) Link to comment Share on other sites More sharing options...
daniro Posted October 9, 2015 Author Share Posted October 9, 2015 I will input enable The text object like you said, I need the player to click on them.Really appreciate your help Rich, thank you for the fast reply Link to comment Share on other sites More sharing options...
daniro Posted October 9, 2015 Author Share Posted October 9, 2015 Rich, i tried the solution and it worked like a charm, thank you. Link to comment Share on other sites More sharing options...
Recommended Posts