Golem Particle

Golem Particle has come back! After adding many new functions and polishing previous ones, I’ve upgraded Golem Particle. Before, there were many functions that were imperfect, or required unnecessary typing to do. I’ve changed it so that you have to use a minimal amount of code to make pretty good particle effects. You will need the Transition Library by TimeSpaceMagic, if you have it already, duplicate it and save it as “transitions.lua”. You must do this because you can interfere with Golem Particle’s transitions if you cancel all transitions or pause them all. Documentation of Golem Particle is given below.

For the library

Getting Started:

To start using Golem Particle, put this at the top of the scene you’ll use it in:
[lua]local gp=require(“golem_particle”)[/lua]
That way, you can use all the functions from it.
RADIAL VENTS:

A Radial Vent has particles that start at the center and then move within a radius.
Making the vent:

[lua]local myRadialVent=gp.newRadialVent{

–“shape” parameter:
shape={“rect”, 20, 20}, --> Particles are rectangles, 20x20
–shape={“circle”, 5, 10} --> Particles are circles with a random radius from 5 pixels to 10 pixels
–shape={“image”, “myParticleImage.png”, 10, 10} --> Particles are “myParticleImage.png” image rectangles, 10x10

–“radius” parameter:
radius=150, --> Particles must be inside a radius of 150

–“ventSpeed” parameter:
ventSpeed=100, --> Vent makes new burst of particles every 100 milliseconds

–“particleSpeed” parameter:
particleSpeed=1000, --> Particles take 1000 milliseconds to reach their destination

–“numParticles” parameter:
numParticles=10, --> Every burst will make 10 particles

–“life” parameter:
life=1500, --> It will take 1500 milliseconds for the particle to reach the endScale and endAlpha and be destroyed

–“endAlpha” parameter:
endAlpha=0, --> Alpha the particle will be when it is destroyed

–“endScale” parameter
endScale={0.5, 0.5} --> xScale and yScale the particle will be when it is destroyed

}[/lua]

Functions for Radial Vents:

“setParticleColor” function:
[lua] myRadialVent:setParticleColor(255,255,255) --> Particles are white
–myRadialVent:setParticleColor(255,255,255,80) --> Particles are white with 80 alpha

–Random fillColors:
–myRadialVent:setParticleColor(0,255, 0,255, 0,255) --> Particles have random color, bounds are in pairs
–myRadialVent:setParticleColor(255,255, 100,255, 255,255) --> Particles have 255 red, a random value from 100 to 255 green, and 255 blue
–myRadialVent:setParticleColor(85,150, 255,255, 255,255, 0,255) --> Particles have a random value from 85 to 150 red, 255 green, 255 blue, and a random value from 0 to 255 alpha
–myRadialVent:setParticleColor() --> Entirely random[/lua]

“setParticleShape” function:
[lua] myRadialVent:setParticleShape{
–Can set same parameters as “shape” parameter in newRadialVent function
–You have to re-activate the vent with “activate” for changes to take effect
}[/lua]

Note: All values can be changed like this:
[lua] myRadialVent.endAlpha=1.0[/lua]

“activate” function:
[lua] myRadialVent:activate() --> Begin spawning particles![/lua]

“deactivate” function:
[lua] myRadialVent:deactivate() --> Stop spawning particles[/lua]
PHYSICS VENTS:

A physics vent (ironically) does not use physics. But you can customize it so that it looks like it does. Create fountains, flares, or whatever that has a physics effect.

Making the vent:

[lua]local myPhysicsVent=gp.newPhysicsVent{

–“shape” parameter:
shape={“rect”, 20, 20}, --> Particles are rectangles, 20x20
–shape={“circle”, 5, 10} --> Particles are circles with a random radius from 5 pixels to 10 pixels
–shape={“image”, “myParticleImage.png”, 10, 10} --> Particles are “myParticleImage.png” image rectangles, 10x10

–“ventSpeed” parameter:
ventSpeed=100, --> Vent makes new burst of particles every 100 milliseconds

–“numParticles” parameter:
numParticles=10, --> Every burst will make 10 particles

–“forceX” parameter:
forceX=15, --> Amount of movement to either side the particle will start with

–“growthRate” parameter:
growthRate=5, --> A little “boost” for the forceX

–“gravity” parameter:
gravity={0, 4}, --> It is what it says, first value is x, second value is y

–“initForce” parameter:
initForce={10, 30}, --> How high up it will fly (in random bounds), negative values make force go down

–“life” parameter:
life=1500, --> It will take 1500 milliseconds for the particle to reach the endScale and endAlpha and be destroyed

–“endAlpha” parameter:
endAlpha=0, --> Alpha the particle will be when it is destroyed

–“endScale” parameter
endScale={0.5, 0.5} --> xScale and yScale the particle will be when it is destroyed

}[/lua]

Functions for Physics Vents:

“setParticleColor” function:
[lua] myPhysicsVent:setParticleColor(255,255,255) --> Particles are white
–myPhysicsVent:setParticleColor(255,255,255,80) --> Particles are white with 80 alpha

–Random fillColors:
–myPhysicsVent:setParticleColor(0,255, 0,255, 0,255) --> Particles have random color, bounds are in pairs
–myPhysicsVent:setParticleColor(255,255, 100,255, 255,255) --> Particles have 255 red, a random value from 100 to 255 green, and 255 blue
–myPhysicsVent:setParticleColor(85,150, 255,255, 255,255, 0,255) --> Particles have a random value from 85 to 150 red, 255 green, 255 blue, and a random value from 0 to 255 alpha
–myPhysicsVent:setParticleColor() --> Entirely random[/lua]

Note: All values can be changed like this:
[lua] myPhysicsVent.ventSpeed=1000[/lua]

“setParticleShape” function:
[lua] myPhysicsVent:setParticleShape{
–Can set same parameters as “shape” parameter in newPhysicsVent function
–You have to re-activate the vent with “activate” for changes to take effect
}[/lua]

“activate” function:
[lua] myPhysicsVent:activate() --> Begin spawning particles![/lua]

“deactivate” function:
[lua] myPhysicsVent:deactivate() --> Stop spawning particles[/lua]

Enjoy!
[import]uid: 147322 topic_id: 28387 reply_id: 328387[/import]

Very promising. However, I get the following error when compiling

golem_particle.lua:20: module ‘transitions’ not found:resource (transitions.lu) does not exist in archive
no field package.preload[‘transitions’]

Are you using a custom transitions library?

Thanks for sharing.

[import]uid: 74786 topic_id: 28387 reply_id: 118505[/import]

I’m so sorry! I forgot to link to the page! If you look back, I’ve added a link. [import]uid: 147322 topic_id: 28387 reply_id: 118507[/import]

Please tell me if you’d like me to add something here. [import]uid: 147322 topic_id: 28387 reply_id: 114975[/import]

Thanks. I have it up and running in my game. Now, I am seeing an error after I deactivate a radial emitter.

Runtime error
…trunk/golem_particle.lua:182: attempt to call method ‘insert’ (a nil value)
stack traceback:
[C]: in function ‘insert’
…trunk/golem_particle.lua:182: in function ‘_listener’
?: in function <?:514>
?: in function <?:215>
Runtime error
…trunk/golem_particle.lua:191: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
…trunk/golem_particle.lua:191: in function <…trunk>
(tail call): ?
?: in function <?:1187>
?: in function <?:215>

My guess is that I am not stopping the emitter properly before removing it. Have you encountered this error before?
[import]uid: 74786 topic_id: 28387 reply_id: 118538[/import] </…trunk>

No, I haven’t. I’ll retry it and see. [import]uid: 147322 topic_id: 28387 reply_id: 118549[/import]

Thanks for sharing this with the community :slight_smile:

One suggestion, create a github repo for this to make distributing it easier, splitting it into several pastes on the code base isn’t ideal.

Keep it up ! [import]uid: 84637 topic_id: 28387 reply_id: 118568[/import]

Yeah, I’m having some trouble figuring out how to use github, but I’ll update it when I get it. [import]uid: 147322 topic_id: 28387 reply_id: 118687[/import]

Hey, @neufdoigts:
I’ve just tried it again, and I’m not getting an error. Could you please give me exactly what you are doing? Please note: If you are deactivating it and then instantly changing scenes, it could have some problems with that. I’ll try to deal with that with the next update. Otherwise, I don’t know what’s happening.

quinc [import]uid: 147322 topic_id: 28387 reply_id: 118690[/import]

Hi quinc,
Thanks for getting back to me. Yeah, I was deactivating and then immediately changing scenes. From what I could tell, the problem stemmed from burst and killParticle functions continuing to be called even after the display items had been removed. I ended up tracking the burst timer with a new variable and then canceling it on deactivation

-- in the burst function  
physVent.burstTimer = timer.performWithDelay(0, burstI, physVent.numParticles)  
  
-- modifed deactivation  
function physVent:deactivate()  
 print("physVent:deactivate")  
 if (physVent.particleTimer) then  
 timer.cancel(physVent.particleTimer)  
 end  
 if (physVent.burstTimer) then  
 timer.cancel(physVent.burstTimer)  
 end  
end  

Then I created a new function to clear out particles in existence.

function physVent:clearParticles()  
 print("physVent:clearParticles")  
 for i=1, physVent.numChildren do  
 local particle = physVent[i]  
 if (particle) then  
 if(particle.lifeTimer) then  
 transitionCancel(particle.lifeTimer)  
 end  
 if(particle.reposTimer) then  
 timer.cancel(particle.reposTimer)  
 end  
 particle:removeSelf()  
 particle=nil  
 end  
 end  
end  

Not pretty but it did the job. It may not be a typical case to want to remove the particles abruptly like I did. Most users probably just want to turn on and off the emitters during gameplay to get the desired fx.

Thanks again for sharing your code.

[import]uid: 74786 topic_id: 28387 reply_id: 118701[/import]

Well, glad you solved your problem. I’ll try adding a purge function, for that sort of thing. So are you having any other issues? [import]uid: 147322 topic_id: 28387 reply_id: 118708[/import]

Nothing yet although I haven’t finished testing. Will let you know if something comes up. [import]uid: 74786 topic_id: 28387 reply_id: 118729[/import]