old_blueyes Posted October 30, 2018 Share Posted October 30, 2018 Hi, Having problems using .destroy() to remove a group. Am i using it wrong? Is there an alternative I should use? I've tried .kill() and .remove() and they don't work either, my code is below. Destroy is at the very bottom in the hideCommentaryBox() function. preload() { } create() { this.timedEvent = this.time.addEvent({ delay: 1500, callback: this.singleLineCommentary, callbackScope: this}); } update() { } singleLineCommentary() { this.showCommentaryBox("HELLO THERE! Put Some Text Here!"); this.timedEvent = this.time.addEvent({ delay: 4500, callback: this.hideCommentaryBox, callbackScope: this}); } showCommentaryBox(text) { if (this.commBox) { this.commBox.destroy(); } var commBox = this.add.group(); var rect = new Phaser.Geom.Rectangle(0, (960*scaleFactor), windowWidth, 70); var commBack = this.add.graphics({ fillStyle: { color: 0x0000ff } }); commBack.fillRectShape(rect); rect.depth += windowHeight; var style = { fontSize: 24, fontFamily: 'Arial', align: "center" } var commText = this.add.text(windowWidth / 2, (1020*scaleFactor), text, style).setOrigin(0.5, 0.5); commBox.add(commBack); commBox.add(commText); this.commBox = commBox; } hideCommentaryBox() { console.log('hide'); this.commBox.destroy(); } Link to comment Share on other sites More sharing options...
prob Posted October 30, 2018 Share Posted October 30, 2018 this.commBox.destroy(true); destroyChildren old_blueyes 1 Link to comment Share on other sites More sharing options...
old_blueyes Posted October 30, 2018 Author Share Posted October 30, 2018 Thanks, just tried it and it worked ? Strangely though, i'm sure I tried this last night and it didn't work. ? Link to comment Share on other sites More sharing options...
Recommended Posts