Sequences and Parallels

You will need to have this import statement to use Sequences and Parallels.

from direct.interval.IntervalGlobal import *

Sequences and Parallels can control when intervals are played. Sequences play intervals one after the other, effectively a “do in order” command. Parallels are a “do together,” playing all intervals at the same time. Both have simple formats, and every kind of interval may be used.

mySequence = Sequence(myInterval1, ..., myIntervaln, name="Sequence Name")
myParallel = Parallel(myInterval1, ..., myIntervaln, name="Parallel Name")

To add to sequences or parallels after creating them, use the append method.


Sequences and Parallels may also be combined for even greater control. Also, there is a wait interval that can add a delay to Sequences. While it can be defined beforehand, it does not have to be.

delay = Wait(2.5)
pandaWalkSeq =
        Parallel(pandaWalk, pandaWalkAnim),
        Parallel(pandaWalkBack, pandaWalkAnim),
        Func(myFunction, arg1)

In the above example, a wait interval is generated. After that, a Sequence is made that uses a Parallel, the defined wait interval, another Parallel, and a wait interval, and a call to the function function myFunction is generated in the Sequence. Such Sequences can get very long very quick, so it may be prudent to define the internal Parallels and Sequences before creating the master Sequence.

One can do very powerful things with Sequences and Parallels. Examine this Sequence:

s = OnscreenImage('wav_is_playing.png')
fadeIn = s.colorScaleInterval(3, (1, 1, 1, 1), (1, 1, 1, 0))
fadeOut = s.colorScaleInterval(3, (1, 1, 1, 0))
sound = loader.loadSfx('sound.wav')


It fades an image in, plays a sound, waits till sounds stops and then fades the image out. Doing this conventional way would require a class to store state, a task to check timings, and produce messy code.