Inserting an emitter into a display group

How do I insert an emitter into a display group?
Is this the correct way?

[lua]Particles.CreateEmitter(“E1”, screenW*0.05, screenH*0.5, 90, false, false)
E = Particles.GetEmitter(“E1”)
yGroup:insert(E)[/lua]

Because no particles are emitted when I use the above code. The Particle count stays at 0. When I comment out the third line(insert function), it works fine; the emitter emits particles.

What am I missing here? [import]uid: 64174 topic_id: 14553 reply_id: 314553[/import]

Can you show more code? That looks correct. Did you start the emitter? Did you print the group (yGroup.numChildren) and check that? [import]uid: 40033 topic_id: 14553 reply_id: 53838[/import]

[lua]module(…, package.seeall)
function fireEmit:fire(myGroup,yPosition)

display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR

– LOAD PARTICLE LIB
local Particles = require(“lib_particle_candy”)

local screenW = display.contentWidth
local screenH = display.contentHeight

local BG = display.newImage(“background.png”)

local StatusText = display.newText( " ", screenW/2, screenH-20, native.systemFont, 12 )
StatusText:setTextColor( 255,255,255 )

– CREATE EMITTERS (NAME, SCREENW, SCREENH, ROTATION, ISVISIBLE, LOOP)
Particles.CreateEmitter(“E1”, screenW*0.05, screenH*0.5, 90, false, true)
E = Particles.GetEmitter(“E1”)
myGroup:insert(E)

– DEFINE PARTICLE TYPE PROPERTIES
local Properties = {}
Properties.imagePath = “flame.png”
Properties.imageWidth = 32 – PARTICLE IMAGE WIDTH (newImageRect)
Properties.imageHeight = 32 – PARTICLE IMAGE HEIGHT (newImageRect)
Properties.velocityStart = 150 – PIXELS PER SECOND
Properties.alphaStart = 0 – PARTICLE START ALPHA
Properties.fadeInSpeed = 2.0 – PER SECOND
Properties.fadeOutSpeed = -0.5 – PER SECOND
Properties.fadeOutDelay = 1000 – WHEN TO START FADE-OUT
Properties.scaleStart = 0.5 – PARTICLE START SIZE
Properties.scaleVariation = 0.5 – RANDOMLY ADDED SCALE VARIATION
Properties.scaleInSpeed = 1.5 – PARTICLE SCALE-IN SPEED
Properties.rotationVariation = 360 – RANDOM ROTATION
Properties.rotationChange = 30
Properties.weight = 0 – PARTICLE WEIGHT (>0 FALLS DOWN, <0 WILL RISE UPWARDS)
Properties.bounceX = false – REBOUND FROM SCREEN LEFT & RIGHT BORDER
Properties.bounceY = false – REBOUND FROM SCREEN TOP & BOTTOM BORDER
Properties.bounciness = 0.75 – REBOUND ENERGY
Properties.emissionShape = 0 – 0 = POINT, 1 = LINE, 2 = RING, 3 = DISC
Properties.emissionRadius = 140 – SIZE / RADIUS OF EMISSION SHAPE
Properties.killOutsideScreen = true – PARENT LAYER MUST NOT BE NESTED OR ROTATED!
Properties.lifeTime = 4000 – MAX. LIFETIME OF A PARTICLE
Properties.autoOrientation = false – AUTO-ROTATE INTO MOVEMENT DIRECTION
Properties.useEmitterRotation = false --INHERIT EMITTER’S CURRENT ROTATION
Properties.blendMode = “add” – SETS BLEND MODE (“add” OR “normal”, DEFAULT IS “normal”)
Particles.CreateParticleType (“Flame”, Properties)

– DEFINE PARTICLE TYPE PROPERTIES
local Properties = {}
Properties.imagePath = “smoke.png”
Properties.imageWidth = 32 – PARTICLE IMAGE WIDTH (newImageRect)
Properties.imageHeight = 32 – PARTICLE IMAGE HEIGHT (newImageRect)
Properties.velocityStart = 100 – PIXELS PER SECOND
Properties.velocityVariation = 50
Properties.alphaStart = 0 – PARTICLE START ALPHA
Properties.fadeInSpeed = 2.0 – PER SECOND
Properties.fadeOutSpeed = -0.5 – PER SECOND
Properties.fadeOutDelay = 1000 – WHEN TO START FADE-OUT
Properties.scaleStart = 0.5 – PARTICLE START SIZE
Properties.scaleVariation = 0.5 – RANDOMLY ADDED SCALE VARIATION
Properties.scaleInSpeed = 2 – PARTICLE SCALE-IN SPEED
Properties.rotationVariation = 360 – RANDOM ROTATION
Properties.rotationChange = 30
Properties.weight = 0 – PARTICLE WEIGHT (>0 FALLS DOWN, <0 WILL RISE UPWARDS)
Properties.bounceX = false – REBOUND FROM SCREEN LEFT & RIGHT BORDER
Properties.bounceY = false – REBOUND FROM SCREEN TOP & BOTTOM BORDER
Properties.bounciness = 0.75 – REBOUND ENERGY
Properties.emissionShape = 0 – 0 = POINT, 1 = LINE, 2 = RING, 3 = DISC
Properties.emissionRadius = 140 – SIZE / RADIUS OF EMISSION SHAPE
Properties.killOutsideScreen = true – PARENT LAYER MUST NOT BE NESTED OR ROTATED!
Properties.lifeTime = 4000 – MAX. LIFETIME OF A PARTICLE
Properties.autoOrientation = false – AUTO-ROTATE INTO MOVEMENT DIRECTION
Properties.useEmitterRotation = false --INHERIT EMITTER’S CURRENT ROTATION
Particles.CreateParticleType (“Smoke”, Properties)

– FEED EMITTERS (EMITTER NAME, PARTICLE TYPE NAME, EMISSION RATE, DURATION, DELAY)
Particles.AttachParticleType(“E1”, “Flame”, 7, 9999,0)
Particles.AttachParticleType(“E1”, “Smoke”, 7, 9999,0)

– TRIGGER THE EMITTERS
Particles.StartEmitter(“E1”)
local Emitter1 = Particles.GetEmitter(“E1”)

– ATTRACTION FIELD
Particles.CreateFXField(“F1”, 0, screenW*0.5,screenH*0.5, 1.5, 140, false)


– MAIN LOOP

local function main( event )

– MOVE EMITTER
Emitter1.x = 220
Emitter1.y = yPosition

– UPDATE PARTICLES
Particles.Update()

– DISPLAY PARTICLE COUNT
StatusText.text = “PARTICLES:”…Particles.CountParticles()
end

Runtime:addEventListener( “enterFrame”, main )

end[/lua]

This is the fireEmit.lua file which I use. It is a slightly modified version of the Sample_Visuals_Flame example. Line 20 is where I insert the emitter into the group myGroup. I call the FireEmit function from main.lua

[lua]local fireEmit = require “fireEmit”
myGroup = display.newGroup()
–Add some objects in group
fireEmit:fire(myGroup,100)[/lua]
[import]uid: 64174 topic_id: 14553 reply_id: 53845[/import]

Sorry for hijacking this thread as I have had no useful replies to my thread on the same subject.
I have a simple emitter that works perfectly as I require it, but when I include the line to add the emitter to a display group it just hangs with an error.
The display group is set up with the following line:
[lua]flashystuff = display.newGroup()[/lua]
and when the emitter is created:
[lua]Particles.CreateEmitter(“eFood”, foodx, foody, 90, false, false)
Particles.SetEmitterTarget(“eFood”, food, false, 0)
flashystuff:insert( Particles.GetEmitter(“efood”) )[/lua]

Like I said, if the insert line is left out then it works fine, but trying to insert the emitter into the ‘flashystuff’ display group returns the following error:

Runtime error  
 /Users/home/Desktop/coroner/main.lua:84: ERROR: table expected. If this is a function call, you might have used '.' instead of ':'  
stack traceback:  
 [C]: ?  
 [C]: in function 'insert'  
 /Users/home/Desktop/coroner/main.lua:84: in function 'initGame'  
 /Users/home/Desktop/coroner/main.lua:14: in function   
 ?: in function <?:214>  

Any help would be appreciated.

[edit]
Ignore me. Reading back through that after just posting it jumped right out at me that I’d used ‘efood’ instead of ‘eFood’. Thanks anyway :slight_smile: [import]uid: 7841 topic_id: 14553 reply_id: 54365[/import]

@Appletreeman:

[lua]Particles.CreateEmitter(“eFood”, foodx, foody, 90, false, false)
Particles.SetEmitterTarget(“eFood”, food, false, 0)
flashystuff:insert( Particles.GetEmitter(“efood”) )[/lua]

Did you realize that there is a typo in your code (notice the last line where it says “efood” instead of “eFood”)?

Otherwise it should work. Just insert any emitter into a group and it’s particles will be drawn inside this group then. [import]uid: 10504 topic_id: 14553 reply_id: 55333[/import]