Qzlmnrk Posted November 20, 2014 Share Posted November 20, 2014 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 More sharing options...
rtlehr Posted November 20, 2014 Share Posted November 20, 2014 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 = otherThingtimer = gametimer + ARBITRARY AMOUNT Then in the update function you If(timer >= gametimer && destoryMe != null){ destroyMe.destroy(); 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. Ross Link to comment Share on other sites More sharing options...
lewster32 Posted November 20, 2014 Share Posted November 20, 2014 Phaser creates a Timer instance on game.time for this very purpose:function removeOtherThing(thing, otherThing) { // Add a single-fire timer event to destroy otherThing after 1000ms (1 second) game.time.events.add(1000, function() { otherThing.destroy(); }, this);} rtlehr, sebamawa and Qzlmnrk 3 Link to comment Share on other sites More sharing options...
rtlehr Posted November 20, 2014 Share Posted November 20, 2014 And there it is.... lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts