Display effects in one particular Display Group

Hello Caleb, I,m trying to add some rain effect to my app but want to add it to a specific display group. Is there a way to do that?

I tried the following, where I set the group before calling the initiate() function but it’s not working:

        preset=“rain”,

            title=“rain”,

            scale=1,

            positionType=“inRect”,

            rectLeft=0,

            rectTop=-20,

            rectWidth=display.contentWidth + 40,

            rectHeight=20,

            build=function()

                                local ls = display.newImageRect(“Textures/generic_particle.png”, 2, 35)

                                particletable[1].dgroup:insert(ls)

                                return ls

            end,

            alpha=0.6,

            onDeath=function(p, v, c)

                particletable[1].sampleVGroup:translate(“drop”, p.x, p.y)

                particletable[1].sampleVGroup:emit(“drop”)

            end,

            propertyTable={

                rotation=10

            },

            lifeStart=display.contentHeight * 0.53,

            lifeSpan=40,

            endAlpha=0,

            perEmit=8,

            physics={

Nevermind I found the parentGroup parameter! duh! :slight_smile:

Glad you got it fixed :slight_smile:

  • C

Nevermind I found the parentGroup parameter! duh! :slight_smile:

Glad you got it fixed :slight_smile:

  • C

Hello!How do i display the rain effect in a display group (let’s say weatherGroup) in this code??

heavy_rain=CBE.VentGroup{

        {

            preset=“rain”,

            title=“drop”, – The “plink” effect at the end of each raindrop

            positionType=“atPoint”,

            build=function()

                return display.newImageRect(“Textures/generic_particle.png”, 20, 5)

            end,

            alpha=0.5,

            fadeInTime=0,

            lifeStart=0,

            lifeSpan=100,

            endAlpha=0,

            perEmit=1,

            physics={

                maxX=30,

                sizeX=1, – Grow X like a ripple

                velocity=0 – Don’t move

            }

        },

        {

            preset=“rain”,

            title=“rain”,

            positionType=“inRect”,

            rectLeft=0,

            rectTop=-100,

            rectWidth=display.contentWidth,

            rectHeight=100,

            build=function()

                return display.newImageRect(“Textures/generic_particle.png”, 10, math.random(70,90))

            end,

            alpha=0.5,

            onDeath=function(p, v, c)

                --heavy_rain.sampleVGroup:translate(“drop”, p.x, p.y)

                --heavy_rain.sampleVGroup:emit(“drop”)

                heavy_rain:translate(“drop”, p.x, p.y)

                heavy_rain:emit(“drop”)

            end,

            propertyTable={

                rotation=10

            },

            lifeStart=370,

            lifeSpan=50,

            endAlpha=0,

            perEmit=1,

            physics={

                autoAngle=false,

                angles={265},

                velocity=24

            }

        },

        {

    preset=“fluid”,

    title=“clouds”,

    color={

        {70}, – Dark grays

        {60},

        {50}

    },

    positionType=“inRect”,

    rectLeft=0,

    rectTop=0,

    rectWidth=1024,

    rectHeight=60, – Create a blanket of clouds at the top of the screen

    fadeInTime=500, – Low fade in time and life span

    lifeSpan=500,

    lifeStart=1000, – High life start delay

    build=function()

        local size=math.random(280, 312) – Particles are quite large

        return display.newImageRect(“Textures/generic_particle.png”, size, size)

    end,

    propertyTable={

        blendMode=“normal” – Normal fluid preset uses additive blending via the property table

    },

    physics={

        velocity=1.1, – Some minor velocity in left-right direction

        autoAngle=false,

        angles={180, 0}

    }

    }

    }

–heavy_rain:start(“clouds”,“rain”)

As you can see, the parentGroup parameter does that.

For each vent, add a parentGroup = weatherGroup if you want particles to be added to “weatherGroup”.

  • Caleb

Hello!How do i display the rain effect in a display group (let’s say weatherGroup) in this code??

heavy_rain=CBE.VentGroup{

        {

            preset=“rain”,

            title=“drop”, – The “plink” effect at the end of each raindrop

            positionType=“atPoint”,

            build=function()

                return display.newImageRect(“Textures/generic_particle.png”, 20, 5)

            end,

            alpha=0.5,

            fadeInTime=0,

            lifeStart=0,

            lifeSpan=100,

            endAlpha=0,

            perEmit=1,

            physics={

                maxX=30,

                sizeX=1, – Grow X like a ripple

                velocity=0 – Don’t move

            }

        },

        {

            preset=“rain”,

            title=“rain”,

            positionType=“inRect”,

            rectLeft=0,

            rectTop=-100,

            rectWidth=display.contentWidth,

            rectHeight=100,

            build=function()

                return display.newImageRect(“Textures/generic_particle.png”, 10, math.random(70,90))

            end,

            alpha=0.5,

            onDeath=function(p, v, c)

                --heavy_rain.sampleVGroup:translate(“drop”, p.x, p.y)

                --heavy_rain.sampleVGroup:emit(“drop”)

                heavy_rain:translate(“drop”, p.x, p.y)

                heavy_rain:emit(“drop”)

            end,

            propertyTable={

                rotation=10

            },

            lifeStart=370,

            lifeSpan=50,

            endAlpha=0,

            perEmit=1,

            physics={

                autoAngle=false,

                angles={265},

                velocity=24

            }

        },

        {

    preset=“fluid”,

    title=“clouds”,

    color={

        {70}, – Dark grays

        {60},

        {50}

    },

    positionType=“inRect”,

    rectLeft=0,

    rectTop=0,

    rectWidth=1024,

    rectHeight=60, – Create a blanket of clouds at the top of the screen

    fadeInTime=500, – Low fade in time and life span

    lifeSpan=500,

    lifeStart=1000, – High life start delay

    build=function()

        local size=math.random(280, 312) – Particles are quite large

        return display.newImageRect(“Textures/generic_particle.png”, size, size)

    end,

    propertyTable={

        blendMode=“normal” – Normal fluid preset uses additive blending via the property table

    },

    physics={

        velocity=1.1, – Some minor velocity in left-right direction

        autoAngle=false,

        angles={180, 0}

    }

    }

    }

–heavy_rain:start(“clouds”,“rain”)

As you can see, the parentGroup parameter does that.

For each vent, add a parentGroup = weatherGroup if you want particles to be added to “weatherGroup”.

  • Caleb

Hi I am using your library in my game, I had this code:

    local vent = CBE.VentGroup {positionType = “inRadius”, inTime = 5, outTime = 500, preset = “burn”, x=x, y=y, color = {{255, 255, 0}},
        physics = {
            angles = {{100, 100}},
            scaleRateX = .5,
            scaleRateY = .5,
            gravityY = -0.05
        }
    }
    function destroyVent()
        vent:stop()
        vent = nil
    end
    vent:start()

I have a local group variable like:

local elements = display.newGroup()

and I want to insert the effect on that group, what I did is:

elements:insert( vent)

but shows some error, how can I do that?

One of two ways:

In your vent parameters, you can add this:
[lua]
parentGroup = elements
[/lua]

Or, you can use this:
[lua]
elements:insert(vent.content)
[/lua]

Besides that, though, you’re also using the VentGroup command in a not-so-good way; it’s ok to do that, but if you only have one vent in a VentGroup, you should use the plain ol’ newVent command.

Good Day,

Thanks for your reply I got it worked.

I have another issue with the library and I hope you can help with this.

I use the CBEffects on a storyboard, but I got error everytime I change the scene

error.jpg

What is the right way to start/end the effect?

I start the “burn” effect when the game is over, then end it before I go to the next scene, but I got the above error, I have no idea why I follow your example. Is this incompatible with the storyboard scenes?

Please help,

Thanks

To end the effect instantly (e.g. leaving a scene), you’ll want vent:destroy(). That clears the particles, cancels all the timers, etc.

If you just call vent:stop(), that just stops further particles from being emitted. The particles already on the screen still exist, which is usually why you get that error.

  • Caleb

Good Day,

Thanks it worked

Hi I am using your library in my game, I had this code:

    local vent = CBE.VentGroup {positionType = “inRadius”, inTime = 5, outTime = 500, preset = “burn”, x=x, y=y, color = {{255, 255, 0}},
        physics = {
            angles = {{100, 100}},
            scaleRateX = .5,
            scaleRateY = .5,
            gravityY = -0.05
        }
    }
    function destroyVent()
        vent:stop()
        vent = nil
    end
    vent:start()

I have a local group variable like:

local elements = display.newGroup()

and I want to insert the effect on that group, what I did is:

elements:insert( vent)

but shows some error, how can I do that?

One of two ways:

In your vent parameters, you can add this:
[lua]
parentGroup = elements
[/lua]

Or, you can use this:
[lua]
elements:insert(vent.content)
[/lua]

Besides that, though, you’re also using the VentGroup command in a not-so-good way; it’s ok to do that, but if you only have one vent in a VentGroup, you should use the plain ol’ newVent command.

Hi team ,

i am having the same issue in composer. When I use    vent:destroy() , I got nil value even it is running in the simulator… Any hint ??

Thanks

Abdul

Just to recap, vent:destroy() is equivalent to displayObject:removeSelf() or display.remove(displayObject). You should call it just before leaving a scene.

If you’re already doing that, I’ll need an example of your code. vent:destroy() is working for me.

  • Caleb

Hi Caleb,

What i noticed is the following ,

if i define vent above all functions as global variable and initialise it there then vent:destroy() and other works…

on the other hand , if you create function called for example animate() and include the initialisation of vent inside this function then destroy does not work…

[lua]

local vent – general variable 

– some code

animate() –  start works

– some code

function animate ()

 vent = CBE.newVent {}

 vent:start()  

end

function scene:destroy( event )

   vent:destroy() – does not work

end

[/lua]

thanks 

Abdul

What’s your error?

Make sure that no vent methods are getting called after vent:destroy().

  • Caleb