Jump to content

Remove object in group after delay?


Recommended Posts

I already know how to destroy a group object when it collides with something else.  However, I can't seem to find a way to delay the destruction of the object after the collision.  The following code works for instantly destroying the otherThing in the otherThings group that the thing object overlaps:

game.physics.arcade.overlap(thing, otherThings, removeOtherThing, null, this);function removeOtherThing (thing, otherThing) {	otherThing.destroy();}

What I want to do is delay the destruction of the otherThing object by an arbitrary amount.  I can't seem to find a way that works, though, with the methods I've tried so far returning errors.  Help would be appreciated!

Link to comment
Share on other sites

Just off the top of my head (I'm kinda' new to the phaser world), but want to be active in the forums (this forum needs a little more activity)...  what if you set up something like (pseudo code of course)


if you create a var to hold the time delay


var timer = new timer


a var to hold the otherThing that needs destoryed


var destoryMe = null;


Then in the "removeOtherThing" function you


destoryMe = otherThing

timer = gametimer + ARBITRARY AMOUNT


Then in the update function you


If(timer >= gametimer && destoryMe != null)



  destroyMe = null;




Now, like I said, I'm kinda' new to this, so Phaser may have a function that does all of this, but mayber this can give you a place to start.



Link to comment
Share on other sites


  • Recently Browsing   0 members

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