[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]