Creating behaviors

Every behavior contains:

Mechanics of Behaviors

A custom behavior class implements the initialization and processStimulus methods from the abstract Behavior class. Of course, the custom behavior class also has at least one constructor and may have other methods as well.
Most behaviors will act on a scene graph object to affect the behavior.The object a behavior acts upon is refered to as the object of change. It is through this object, or objects, that the behavior affects the virtual world. While it is possible to have a behavior that does not have an object of change, most do.
The behavior needs a reference to its object(s) of change to be able to make the behavioral changes. The constructor can be used to set the reference to the object of change. If it does not, another method in the custom behavior class must store this information. In either case, the reference is made at the time the scene graph is being constructed, which is the first computation of the behavior.

The initialization method is invoked when the scene graph containing the behavior class becomes live. The initialization method is responsible for setting the initial trigger event for the behavior and setting the initial condition of the state variables for the behavior. The trigger is specified as a WakeupCondition object, or a combination of WakeupCondition objects.
The processStimulus method is invoked when the trigger event specified for the behavior occurs. The processStimulus method is responsible for responding to the event. As many events may be encoded into a single WakeupCondition object (e.g., a variety of keyboard actions may be encoded in a
WakeupOnAWTEvent), this includes decoding the event. The processStimulus method responds to the stimulus, usually by changing its object of change, and, when appropriate, resets the trigger.
The information in this section, Mechanics of Behaviors, is summarized in a recipe for writing custom
behavior classes :

1. write (at least one) constructor
store a reference to the object of change
2. override public void initialization()
specify initial wakeup criteria (trigger)
3. override public void processStimulus()
decode the trigger condition
act according to the trigger condition
reset trigger as appropriate

Complex behaviors may require more programming than is described in the recipe.