spawning and destroying vents

Hello! First of all thank you so much for this wonderful library!

I have a question regarding the creation and destruction of vents.

Suppose I have a simple physics game with a crate. Everytime the crate collides with the floor I want to have an explosion on the collision location. Is the correct way to do this, to create a new vent on each collision with the desired effect, on that collisions location? If so, suppose the following implementation:

local function createExplosion(x, y) local vent = CBE.newVent { preset = "burn", x=x, y=y } local function destroyVent() vent:stop() vent = nil end vent:start() timer.performWithDelay(1000, destroyVent) end createExplosion(150,150)

Will this correctly destroy the created vents so that they can be garbage collected?

I noticed that if you don’t stop a vent it keeps on working even if you lost all references to it (memory leak).

I didn’t know there was a proper vent.destroy() method

I tried vent:destroy() and didn’t look any further, my bad!

Better than that, you should just create one vent with a finite emissionNum, position it, and start() it each time you want an explosion.

Your approach is fine, but it might get a little slow if you have a bunch of explosions starting with little delay between them.

  • C

I didn’t know there was a proper vent.destroy() method

I tried vent:destroy() and didn’t look any further, my bad!

Better than that, you should just create one vent with a finite emissionNum, position it, and start() it each time you want an explosion.

Your approach is fine, but it might get a little slow if you have a bunch of explosions starting with little delay between them.

  • C