Sometimes we want to cause ParticleEmitters or NodeEmitters to emit objects when a script event fires. One way to do this is via the 'emitBurst()' function. Here's an example of emitting some particles when an object goes through a Trigger. Note that for this example, we'll want to clear the 'Pulse' property of the 'Continuous' group found under the ParticleEmitter's properties to make sure it doesn't also emit on its own. Also, for these examples, ensure to make the ParticleEmitter a child of the Trigger since the code tries to find it within the Trigger's children.
Here's the code snippet:
function Trigger:onEnter(obj) emitter = self:findNodeByName("ParticleEmitter") emitter:emitBurst(100) end
In the above example, a burst of 100 particles is emitted all at once. If we wanted to stream a group of particles, we could activate the ParticleEmitter's pulse for an amount of time, then deactivate it. For this next example, make sure the ParticleEmitter has a Pulse defined under its 'Continuous' property group. We'll also want to make sure the Pulse's 'Active' property is set to 'false'.
function Trigger:onEnter(obj) emitter = self:findNodeByName("ParticleEmitter") -- Activate emitter now emitter.continuous.pulse.active = true -- Create a 2 second timer then call our onTimeOut() function getAnimator():createTimer(self, self.onTimeOut, seconds(2)) end function Trigger:onTimeOut() emitter = self:findNodeByName("ParticleEmitter") -- Deactivate emitter emitter.continuous.pulse.active = false end