Behavior

Life cycle

A Behavior has a very simple lifecycle. If the Behavior is not cycling, the developer has the option of being notified on Behavior expiration by adding a listener to it. This is a simple triggering mechanism by which you will get informed of which Behavior has expired, and at exactly what time. The behavior listener can also be notified every time the behavior has been applied. A behavior is guaranteed to apply the final value it is defined for.

A behavior listener is an object of the form:

                            {
                                behaviorExpired : function( behavior, time, actor);
                                behaviorApplied : function( behavior, time, normalizedTime, actor, value);
                            }
                        
Note that any behavior can have an arbitrary number of observers.

A behavior observer will be added by calling addListener( behavior_listener_object ).

The behavior listener object function behaviorExpired parameters are:

  1. The CAAT.Behavior object that just expired.
  2. The CAAT.Scene object time the CAAT.Behavior just expired at.
  3. The CAAT.Actor the CAAT.Behavior was acting upon.

and for the function behaviorApplied parameters are:

  1. The CAAT.Behavior object that just expired.
  2. The CAAT.Scene object time the CAAT.Behavior just expired at.
  3. The behavior related time it was applied at.
  4. The CAAT.Actor the CAAT.Behavior was acting upon.
  5. The behaviors value that has been applied.

In this example, two behaviors are set for an actor. When on ebehavior expires, the other one is started and vice versa: