Controlling the Animation Rate

A custom behavior object typically controls the display of objects in a model that supports animation. However, it is the IDLitWindow object that controls the timing of the animation, and notifies the behavior object that it is time to initiate an action. To define what behaviors are initiated when a timer event occurs, add one or more behavior objects to the AddWindowEventObserver method observer list.

To enable timer events for a window, you need to use the SetEventMask method. This effectively lets you to turn on or turn off an animation by enabling or disabling a window's ability to respond to timer events. (Use the GetEventMask method to determine which events are enabled in a window.)

The SetTimerInterval method determines the animation rate. Use the SetTimerInterval method to set a value that specifies how many seconds pass before the next timer event occurs. In the following sample code, oAnimBehavior is the custom behavior object, oAnimationModel is the model that contains the animation, and oWin is an IDLitWindow object.

; Create a custom animation object and initialize it with   
; the animation model. Add the new object to the list 
; of window observers and set the display rate (10 frames 
; per second). 
oAnimBehavior = OBJ_NEW('MyAnimation', oAnimationModel) 
oWin->AddWindowEventObserver, oAnimBehavior 
oWin->SetTimerInterval, 0.1 
 
; Play the animation. 
oWin->SetEventMask, /TIMER_EVENTS 

To turn off an animation, set TIMER_EVENTS equal to 0.

The SetTimerInterval method interval value determines how often an IDLitWindow object calls the OnTimer method for the behavior objects in the observer list. Therefore, each animation behavior object must implement the OnTimer method. See Designing a Behavior Object for more information.