Glimmr Canvas Animation
version 1/111030 by Erik Temple
Chapter: Animation and the timer
Animations are controlled by the Glulx virtual machine's timer functionality. The Glulx timer is global--there is only one "ticker"--but GCA uses "virtual timers" to allow simultaneous animations to run at different speeds.
When only one animation is running, or when all running animations are running at the same rate, then each tick of the global timer represents one "frame" of animation. When we specify multiple rates of animation, however, GCA works out how to subdivide the timer interval so that each animation fires at the requested rate. For example, if we trigger Animation A at 80 milliseconds per frame, and Animation B at 160 milliseconds per frame, then the timer will fire at 80 milliseconds per frame, with Animation A firing every frame, and Animation B every 2 frames.
Users of Glimmr Canvas Animation's animation tracks will rarely if ever need to deal with the timer directly, as the commands for invoking animation tracks automate the process. If needed, though, we can find out what the current interval between ticks of the global timer is by referring to the "global timer interval" global variable (the timer for any given animation track can be got at by checking the "timer interval" property of the track):
say "The interval between ticks is [global timer interval] milliseconds."
The "global timer interval" variable is dynamic: it only contains a value when there is a timer running, and resets to zero when the timer stops. Note that we should *never change* the variable directly; doing so will not change the interval. If we want to set a new interval, we simply need to invoke an animation track, or change the timer directly, like so:
start a Glulx timer of 200 milliseconds
Any time we start a new timer, GCA will look at any animations that may be running and adjust the rate we've requested to maintain their rates. It is probably best never to set the timer directly when animations are involved--just use the "animate..." phrases, detailed below, to trigger animations.
The timer can, of course, run independently of animations. If we want to use the timer for some other purpose in our game, we are welcome to simply start the timer using the same phrase, without using an animation preset. Animations are not activated unless we specifically start them with an animation phrase. It is not a good idea to try to use timed events for other purposes while animations are running--when animations are running, the virtual timer system is invoked, which may cause unpredictability in timed behaviors that don't take that system into account. You can study the source code to see how you might take the system into account, but the easiest way to deal with the situation is to use custom animation tracks--see the chapter on custom animation below--to control all of your non-graphical timed events. This will allow them to use the virtual timer system.
To stop *all* running timers, use:
pause the Glulx timer
Warning: This will stop the timer, but any animations that are running will still be marked as active. If you start another timer, they will begin again, and they will also be factored into the virtual timer system.