Game Development Reference
In-Depth Information
How it works...
Once triggered,
Timer
works by checking the time that has passed since it was started
(
time
). It then checks each of the events in the
timerEvents
map to see whether their
execution time is anywhere between the current time and the last time (
lastTime
). The
maxTime
option is used by the
Timer
to know when it has executed the last of its events
and can switch itself off. If the
Timer
was only meant to be used once, the events can
simply be removed from the
timerEvent
map. This way it can be reused.
The
PlayEffect
instance has a fairly simple functionality to turn it on and off. Since
ParticleEmitters
can be used in two ways, fire all their particles at once, or emit a
continuous stream of particles, it needs to know which way to fire it.
In the example application, we create
ScriptAppState
since it's needed to update the
Timer
with the passed time. We don't need to add the
PlayEffect
instances since they
don't use the
update
method.