Recording Animation

In recorded animation, model variables are set from stored values. A few uses are recording human motion (mouse movement) and recording incremental animation. Recording incremental animation would then let you play it back with the kind of control parametric animation gives. You could also get ahold of some motion-capture data and massage it into a form that can be used for playback within Director.

The recording of the animation may be done as part of the program, or done beforehand. If it is done beforehand, the data needs to be saved, most conveniently in a field or text cast member, and then retrieved at run-time. For saving lists in text form, see the Lingo functions string() and value().

Playback of recorded motion is essentially a parametric animation, with the parameter driving an index into the list of recorded values.

This demo allows the user to record a piece of incremental animation, and then play it back with a slider driver. The animation is a combination of collision and general gravity.

on startRecording()
recordList = [:]
repeat with sp in instanceList
recordList[sp] = []
end repeat
state = #recording

on record()
repeat with sp in instanceList
recordList[sp].add([#x: sp.x, #y: sp.y])
end repeat

on playBack(p) — p:0->1
totalPos = recordList[1].count
index = integer(p * (totalPos – 1) + 1) –index:1->totalPos
repeat with sp in instanceList
pos = recordList[sp][index]
sp.x = pos.x
sp.y = pos.y
end repeat

Methods from script “modelManager”

In this demo the recording is done by a script adapted from the modelRate script in Independent Model Rate, and renamed modelManager. The three methods above show how it does recording and playback.

Notice that the variables recorded are the animation model variables, not the sprite properties. This is generally the best way to go, for several reasons:

  • less information to record. For example, in 3D the x, y, and z coordinates are used to set more than three sprite properties. Of course, this means that during playback a rendering algorithm will still be needed.
  • more importantly, at playback you still have control over rendering.

The variables are recorded once each movie frame in this demo, rather than once each model frame. In this demo the model rate is about 20 times the movie rate. If you wanted to do “super slo-mo” playback, you could record the variables based on model frames, and at slow playback you’ll get a smoother motion.

To record the movement of the mouse, use a script that keeps its x and y animation model variables at the mouse location, and pass the script instance to modelManager’s addInstance() method.

Miscellaneous Points
This is the property list used by modelManager to record the x and y variables of each recorded object. The unusual thing about it is that the keys in the list are object references. recordList associates each object reference with the linear list of recorded position settings for that object.

Usually in sample code the keys are symbols, but the property list can be used to associate values of any data type with each other. This is generally called a hash table, and most likely property lists are implemented in Director using a hash table of some sort.

If recordList is saved in a text cast member, retrieving the list using value() will not recreate object references. To save recordList, use something like sprite numbers for the keys instead of references.

Animation Anomalies
If you watch the animation long enough you’ll notice some interesting anomalies in the behavior of the objects. When I have time I’ll try to pinpoint what is happening. There may or may not be a perfect fix.

Things To Try
Make the playback “instant replay” style by using a time driver instead of a slider to control the playback. You might use a slider to control the speed of the replay.

Tagged on: ,

Leave a Reply

Your email address will not be published. Required fields are marked *