CBE vent gives errors when game scene reloads

So I am using Dusk and CBE and I use CBE’s newVent as a death animation to all enemies.

I noticed that if the death animation is used when played and player dies comes error, BUT if I complete the level and death animation has happened NO error occurs. Odd thing is that when you die/complete level the scene just reloads using composer.gotoScene(“game”). So same scene removal happens on both events.

Here is the error:

[lua]

CBE\cbe_core\vent_core\core.lua:293: attempt to call method ‘insert’ (a nil value)

message

stack traceback:

?: in function <?:221>

[C]: in function ‘insert’

CBE\cbe_core\vent_core\core.lua:293: in function ‘_listener’

?: in function <?:167>

?: in function <?:221>

[/lua] 

And  this is my deathAnimation function:

[lua]

L.deathAnim = function(x,y)

local CBE = require(“CBE.CBE”)

    local vent = CBE.newVent({

            preset = “flame”,

            positionType = “inRadius”,

            color = {{0.1, 0.1, 0.1}, {0.2}, {0.3, 0.3, 0.3}},

            particleProperties = {blendMode = “add”},

            emitX = x,

            emitY = y,

            emissionNum = 1,

            emitDelay = 0,

            perEmit = 3,

            inTime = 100,

            lifeTime = 100,

            outTime = 600,

                    physics = {

                    velocity = 0,

                    gravityY = 0,

                    angles = {0, 360},

            },

                    onCreation = function(particle)

                    particle:changeColor({

                            --color = {0, 1, 0},

                            --time = 600

                    })

            end,

    })

    local map = (require “map”).layer[“ground”]

    map:insert(vent)

    vent:start()

    map=nil

end

[/lua]

Are you making sure to :destroy() the vent at some point?

  • Caleb

No… I was thinking does vent remove itself when completed. Is there onComplete param for this?

I tried the onEmitEnd param to destroy the vent when completed… sadly I don’t know how to destroy vent with it :smiley:

A vent acts as a sort of particle bank. Each time you call :start(), it emits a certain number of particles for a certain amount of time. This means you have to destroy them at some point just as with most display objects:

vent:destroy()

You should destroy the vent before changing scenes.

  • Caleb

How can I use the same vent and emit particles in multiple coordinates…? My deathAnim function now makes everytime a new vent. In this approach I need to use array for the vents to destroy them in loop before scene changes…

I might have understood the vent wrong, got it working now by inserting in table the vents and use destroy function when changing scenes. 

How can I use the same vent and emit particles in multiple coordinates…?

Just set the vent’s emitX and emitY properties to reposition the vent, then :start() it. If you need multiple of the same effect, a technique which has worked for me is to create two vents and use them in a round-robin fashion. You can expand this concept for three vents, four, etc., depending on how many effects you need at the same time.

  • Caleb

Are you making sure to :destroy() the vent at some point?

  • Caleb

No… I was thinking does vent remove itself when completed. Is there onComplete param for this?

I tried the onEmitEnd param to destroy the vent when completed… sadly I don’t know how to destroy vent with it :smiley:

A vent acts as a sort of particle bank. Each time you call :start(), it emits a certain number of particles for a certain amount of time. This means you have to destroy them at some point just as with most display objects:

vent:destroy()

You should destroy the vent before changing scenes.

  • Caleb

How can I use the same vent and emit particles in multiple coordinates…? My deathAnim function now makes everytime a new vent. In this approach I need to use array for the vents to destroy them in loop before scene changes…

I might have understood the vent wrong, got it working now by inserting in table the vents and use destroy function when changing scenes. 

How can I use the same vent and emit particles in multiple coordinates…?

Just set the vent’s emitX and emitY properties to reposition the vent, then :start() it. If you need multiple of the same effect, a technique which has worked for me is to create two vents and use them in a round-robin fashion. You can expand this concept for three vents, four, etc., depending on how many effects you need at the same time.

  • Caleb