in Panda3D, a Sequence is a list of ‘actions’ to be executed in order. Each action in the sequence is executed once and waits for the previous action to finish.
s=Sequence(a,b,c,name="NAME") # to create a sequence s.play() # play once s.loop() # play over and over s.stop() # I'm making this up
Typically, a sequence consists in Intervals. The Panda3D manual has a large chapter dedicated to Intervals. Meanwhile, the Actor class provides easy methods to define intervals for position (pos), rotation (hpr) and scale (scale!).
An interval changes a property (location, rotation, scale, color…) at every frame until that property reaches a specified target value. As you can see, an optional start value can be defined for the property we are interpolating.
Actor posInterval(seconds,Point3(x,y,z), [start=Point3(x0,y0,z0)]) hprInterval(seconds,Vec3(x,y,z)) # in degrees, e.g (180,0,0) scaleInterval(...) posHprInterval(...) posScaleInterval(...) hprScaleInterval(...) posHprScaleInterval(...)
A Parallel uses the same syntax as a sequence. With a parallel, actions are executed in… parallel.
Import statements
# I want to use sequences and parallels from direct.interval.IntervalGlobal import * # I have an actor that I want to move around/rotate from direct.actor import Actor #use actor methods
Wait a second, is that all?
You may have guessed thatĀ Sequence and Parallel inherit from Interval. This allows generating complex, hierarchic sequences.
Sometimes we just need to yield a little bit before playing a sound or doing over things. The Wait interval does just that.
w=Wait(seconds) # defines a 'pause' in a sequence
Finally, theĀ Func interval, lets us call any function as part of a sequence:
f=Func(function[,arg1[,arg2[,...]]])
Use and abuse?
Animation is an art, and you’ll find much more in the Panda3D manual, in the meantime, there’s a couple of points worth raising:
- Where a complex animation is not very interactive, it may not be worth programming at all. What are animation packages for?
- If your animation is very dynamic, consider updating your objects directly using a task (see previous article). Say you were programming boids. How much should we rely on intervals, and how much on intervals and sequences?
That’s it for now.
0 Responses to “Sequences, Parallels & Intervals: Rock your Panda”