old_blueyes

destroy group

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();
 
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.