DirectAnimation Animated Header --Behavior Class DirectAnimation Animated Header --Behavior Class* Microsoft DirectAnimation SDK
*Index  *Topic Contents
*Previous Topic: Bbox3Bvr Class
*Next Topic: BooleanBvr Class

Behavior Class


public class Behavior extends java.lang.Object {
    // Methods
    public Behavior bvrHook(BvrCallback callback);
    public Behavior debug();
    public Behavior debug(String name);
    public Behavior debug(String name, boolean onStart);
    public Behavior debug(String name, boolean onStart, PrintStream std);
    public Behavior duration(NumberBvr length)
    public Object extract();
    public void init(Behavior a);
    public Behavior repeat(int repetitions);
    public Behavior repeatForever();
    public Behavior runOnce();
    public Behavior substituteTime(NumberBvr a);
    
}

All behaviors are potentially time-varying and/or reactive values such as colors, numbers and images. They can be used to construct animated objects. All behavior subclasses inherit the methods of this class.

Because all behaviors are potentially time-varying and/or reactive, their values can change as a function of time or as the result of user input. Time-varying behaviors are created by combining time-based default behaviors (such as localTime) with other behaviors. Reactive behaviors are created using the until, untilEx, and untilNotify methods and specifying input events, such as mouse clicks. Complex behaviors can be built by combining existing behaviors. The value of a complex behavior always depends on the values of the behaviors that comprise it.

Behaviors are started either by the createModel method (which means they start at time = 0) or with the untilNotify.notify method, when they are started at the event time. When a behavior runs, its time-varying and reactive qualities are active. This means the user can experience any changes that occur in the behavior as time passes or events occur.

In order to type-check behaviors, all behavior types must be known at construction time. This is why there is no Behavior.newUninitBvr() method included in the Behavior class.

Behavior Methods

bvrHook
debug()
debug(name)
debug(name, onStart)
debug(name, onStart, std)
duration
extract
init
repeat
repeatForever
runOnce
substituteTime


bvrHook

Behavior Class

Allows a running behavior to be sampled.

public Behavior bvrHook(
  BvrCallback callback
  );

Parameters
callback
The BvrCallback interface containing the notify method.
Return Values

Returns the Behavior object that is the value of the running behavior at the time it was sampled.

See Also

BvrCallback


debug

Behavior Class

Gives the information about a running behavior.

public Behavior debug( );

Remarks

This method gives the following information about a running behavior:

The method assumes the following defaults:

The following example shows that, when it was started, the second instance of a behavior was started at a global time of 39.66 seconds, and had a value of 0.5:


2 started at 39.66 result = 0.5

This method is unavailable to viewers that don't display the standard output.


debug

Behavior Class

Gives information about a running behavior.

public Behavior debug(
  String name
  );

Parameters
name
The name of the behavior.
Return Values

Returns the Behavior object.

Remarks

This method gives the following information about a running behavior:

The method assumes the following defaults:

The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:


"b" 2 started at 39.66 result = 0.5

The next example displays a solid-colored image whose red and green components are 1, and whose blue component is time-varying. The NumberBvr x initially has a value of "b" (a value that varies over time). When the left button of the mouse is pressed, "b" (and therefore, "x" starts all over again, with a value of 0.5.

The debugging information (shown in the previous example) is displayed each time the left mouse button is pressed.


import com.ms.dxmedia.*;

public class DebugTest extends DXMApplet{
  public DebugTest() {
    // Set the model
    setModel(new DebugTestModel()) ;
  } 
}

class DebugTestModel extends Model {
  public void createModel(BvrsToRun extraBvrsToRun) {
      NumberBvr b = (NumberBvr) add(localTime, toBvr(0.5)).Debug("b");

      NumberBvr x = NumberBvr.newUninitBvr();
      x.init(until(b, leftButtonDown, x));
      
      ImageBvr model = solidColorImage(colorRgb(toBvr(1), toBvr(1), x));

      setImage(model);
  }
}       

This method is unavailable to viewers that don't display the standard output.


debug

Behavior Class

Gives information about a running behavior.

public Behavior debug(
  String name,
  boolean onStart
  );

Parameters
name
The name of the behavior.
onStart
If true, the debug method is called when the behavior is started. If false, the method is called whenever the behavior is sampled. The default is true.
Return Values

Returns the Behavior object.

Remarks

This method gives the following information about a running behavior:

This method assumes the information is displayed on the standard output.

The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:


"b" 2 started at 39.66 result = 0.5

This method is unavailable to viewers that don't display the standard output.


debug

Behavior Class

Gives information about a running behavior.

public Behavior debug(
  String name,
  boolean onStart,
  PrintStream std
  );

Parameters
name
The name of the behavior.
onStart
If true, the debug method is called when the behavior is started. If false, the method is called whenever the behavior is sampled. The default is true.
std
The output device. The default is the standard output.
Return Values

Returns the Behavior object.

Remarks

This method gives the following information about a running behavior:

The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:


"b" 2 started at 39.66 result = 0.5

This method is unavailable to viewers that don't display the standard output.


duration

Behavior Class

Creates an animation fragment by associating a local "stop time" with a behavior. The result is a new behavior that is the same as the original behavior for the length of the duration. Once the duration is over, the behavior is a snapshot of the behavior's state when the duration ended.

public Behavior duration(
  NumberBvr length
  )

Parameters
length
The NumberBvr object representing the length of time, in seconds, that the duration lasts. This parameter can also be of type double.
Return Values

Returns the Behavior object.


extract

Behavior Class

Extracts the value of the behavior, returning a Java object. This behavior must have a constant value.

public Object extract( );

Return Values

Returns a Java object. For more information about java.lang.Object objects, consult a Java reference.


init

Behavior Class

Initializes a behavior created by the newUninit method.

public void init(
  Behavior a
  )

Parameters
a
The Behavior object to be initialized.


repeat

Behavior Class

Creates a behavior that repeats itself the number of times specified by repetitions.

public Behavior repeat(
  int repetitions
  );

Parameters
repetitions
The number of times the behavior will repeat.
Return Values

Returns the Behavior object.


repeatForever

Behavior Class

Creates a behavior that repeats infinitely.

public Behavior repeatForever( );

Return Values

Returns the Behavior object.


runOnce

Behavior Class

Used when applications must reference a running behavior once it starts running, but don't require the application to explicitly start that behavior.

public Behavior runOnce( );

Remarks

The following code fragment plays 2 movies. The first movie plays from the beginning for 10 seconds. It then fades, over a 2 second interval, into a second movie. (Assume the existence of a fade method.)

ImageBvr movie1Once = (ImageBvr)movie1.runOnce();
ImageBvr movie2Once = (ImageBvr)movie2.runOnce();
  until(movie1Once,
    timer(toBvr(10)),
      until(fade(div(localTime, toBvr(2)), movie1Once, movie2Once),
        timer(toBvr(2)),
          movie2Once);


substituteTime

Behavior Class

Creates a new behavior from an existing Behavior and a NumberBvr. In the new behavior, the number behavior replaces all occurrences of localTime in the original behavior. (This includes behaviors where localTime is implicit, such as imported movies. The method can be used even if localTime isn't explicitly in the code.)

public Behavior substituteTime(
  NumberBvr a
  );

Parameters
a
The NumberBvr object that replaces localTime.
Return Values

Returns the Behavior object.

Remarks

This method allows behaviors to be, for example, time-scaled to run faster or slower, time-shifted to start at a different time, or frozen at a particular point in time. Here are some examples:

//A point moving 1 unit in x/second, starting at 0	
	b0 = point2(localTime, toBvr(0));

    //Create new behavior moving 0.5 units/second, 
    //by replacing localTime with localTime/2
	b1 = origBvr.substituteTime(div(localTime, toBvr(2)));

    //Create new behavior moving 1 unit/second, 
    //starting at 33, by replacing localTime with localTime + 33
	b2 = origBvr.substituteTime(add(localTime, toBvr(33));

    //Create new behavior moving 2 units/second, starting at 33, 
    //by replacing localTime with (localTime *2) + 33
	b3 = origBvr.substituteTime(add(mul(localTime, toBvr(2)), toBvr(33));

    //Freeze the original behavior at time 77
	b4 = origBvr.substituteTime(toBvr(77));

    //Tie the new behavior to the x-component of the mouse
	b5 = origBvr.substituteTime(mousePosition.getX());

    //Show that replacements are cumulative. The following sequence:
	c0 = point2(localTime, toBvr(0));
	c1 = c0.substituteTime(add(localTime, toBvr(33)));
	c2 = c1.substituteTime(mul(localTime, toBvr(2)));

    //is equivalent to:
	c0.substituteTime(add(mul(localTime, toBvr(2))), toBvr(33));

Relevant Methods from the Statics Class

The following methods are defined in the Statics class and are most relevant to objects of type Behavior.

public static Behavior cond(BooleanBvr bool, Behavior a, Behavior b);

public static Behavior sequence(Behavior a, Behavior b);

public static Behavior until(Behavior a, DXMEvent e, Behavior b);

public static Behavior untilEx(Behavior a, DXMEvent e);

public static Behavior untilNotify(Behavior a, DXMEvent e, UntilNotifier notifier);

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

*Top of Page