Jump to content

destroy group


old_blueyes
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...