wyvern.lib.properties
Class AnimationParams

java.lang.Object
  extended bywyvern.lib.properties.AnimationParams
All Implemented Interfaces:
java.util.EventListener, MapChangeListener, MapLifecycleListener, MutableProperty, Timed

public class AnimationParams
extends java.lang.Object
implements Timed, MutableProperty, MapChangeListener, MapLifecycleListener

Handles object animation.

Version:
1.0, Sep 26, 1997
Author:
Steve Yegge

Field Summary
static int DEFAULT_FRAMES
          The default number of frames for animated objects is 2.
static int DEFAULT_INTERVAL
          The default time between frames is a second or so.
static int SMALLEST_INTERVAL
          The smallest allowable animation interval.
 
Constructor Summary
AnimationParams()
          Constructs a new AnimationParams with the default parameters.
AnimationParams(int frames)
          Constructs a new AnimationParams with the specified number of frames, using the default animation interval.
AnimationParams(int frames, int interval)
          Constructs a new AnimationParams with the specified parameters.
 
Method Summary
 java.lang.Object createClone()
          Produces a clone of the property for the caller.
 void destroy()
          Destroys the AnimationParams, cleaning up any object references, so we don't get memory leaks.
 boolean equals(java.lang.Object other)
          Returns true if two AnimationParams are equivalent.
 int getFrames()
          Returns the number of animation frames for this object.
 int getInterval()
          Returns the animation speed for this object.
 int hashCode()
          Have to override this if you override equals()
 void mapLoaded(MapLifecycleEvent e)
          Invoked when a map is loaded.
 void mapResumed(MapLifecycleEvent e)
          Restarts animation when map is resumed.
 void mapSuspended(MapLifecycleEvent e)
          Stops animation when map is suspended.
 void mapUnloaded(MapLifecycleEvent e)
          Stops animation when map is unloaded.
 void setFrames(int frames)
          Sets the number of frames in this animation.
 void setInterval(int interval)
          Sets the delay between animation frames for this object.
 void start(GameObject obj)
          Starts the animation timer for our object.
 void stop()
          Stops the animation timer for our target.
 void targetEnteredMap(MapChangeEvent event)
          Notification that our target entered a map.
 void targetLeftMap(MapChangeEvent event)
          Notification that our target left a map.
 void timerExpired()
          Called by TimerManager to notify object that timer has expired.
 java.lang.String toString()
          Returns a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FRAMES

public static final int DEFAULT_FRAMES
The default number of frames for animated objects is 2.

See Also:
Constant Field Values

DEFAULT_INTERVAL

public static final int DEFAULT_INTERVAL
The default time between frames is a second or so.

See Also:
Constant Field Values

SMALLEST_INTERVAL

public static final int SMALLEST_INTERVAL
The smallest allowable animation interval. AnimationParams will refuse to set an interval lower than this to avoid degrading game-server performance.

See Also:
Constant Field Values
Constructor Detail

AnimationParams

public AnimationParams()
Constructs a new AnimationParams with the default parameters.


AnimationParams

public AnimationParams(int frames)
Constructs a new AnimationParams with the specified number of frames, using the default animation interval.


AnimationParams

public AnimationParams(int frames,
                       int interval)
Constructs a new AnimationParams with the specified parameters.

Parameters:
frames - the total number of animation frames, including the "base" frame.
interval - the time between frames, in milliseconds
Method Detail

getFrames

public int getFrames()
Returns the number of animation frames for this object.

Returns:
the total number of animations that the object cycles through

setFrames

public void setFrames(int frames)
Sets the number of frames in this animation.

Parameters:
frames - the total number of frames to cycle through

getInterval

public int getInterval()
Returns the animation speed for this object.

Returns:
the delay, in milliseconds, between animation frames

setInterval

public void setInterval(int interval)
Sets the delay between animation frames for this object. If the passed interval is less than SMALLEST_INTERVAL, it will be set to SMALLEST_INTERVAL to avoid degrading server performance.

Parameters:
interval - the delay between frames

start

public void start(GameObject obj)
Starts the animation timer for our object.

Parameters:
obj - the object to animate. It's passed in by setAnimated() in class GameObject. You probably shouldn't call this method directly, but should call GameObject.setAnimated instead.


stop

public void stop()
Stops the animation timer for our target.

If the target is going away permanently, you should call destroy(). Calling MapObject.destroy() takes care of this, if the AnimationParams object is in the target's property list under the name "anima". However, if you're managing the AnimationParams yourself, or you can't call destroy() on your object, you need to call destroy() explicitly, or you'll wind up with a memory leak.


timerExpired

public void timerExpired()
Called by TimerManager to notify object that timer has expired.

Specified by:
timerExpired in interface Timed

targetEnteredMap

public void targetEnteredMap(MapChangeEvent event)
Notification that our target entered a map.

Specified by:
targetEnteredMap in interface MapChangeListener

targetLeftMap

public void targetLeftMap(MapChangeEvent event)
Notification that our target left a map.

Specified by:
targetLeftMap in interface MapChangeListener

mapSuspended

public void mapSuspended(MapLifecycleEvent e)
Stops animation when map is suspended.

Specified by:
mapSuspended in interface MapLifecycleListener

mapUnloaded

public void mapUnloaded(MapLifecycleEvent e)
Stops animation when map is unloaded.

Specified by:
mapUnloaded in interface MapLifecycleListener

mapResumed

public void mapResumed(MapLifecycleEvent e)
Restarts animation when map is resumed.

Specified by:
mapResumed in interface MapLifecycleListener

mapLoaded

public void mapLoaded(MapLifecycleEvent e)
Description copied from interface: MapLifecycleListener
Invoked when a map is loaded.

Specified by:
mapLoaded in interface MapLifecycleListener

toString

public java.lang.String toString()
Returns a String representation of this object.


createClone

public java.lang.Object createClone()
Produces a clone of the property for the caller. Note: it's called createClone, not makeClone, because GameObject already has a makeClone. Some GameObjects can be properties (e.g inventories) and we can't do overloaded methods based only on the return type.

Specified by:
createClone in interface MutableProperty

equals

public boolean equals(java.lang.Object other)
Returns true if two AnimationParams are equivalent.


hashCode

public int hashCode()
Have to override this if you override equals()


destroy

public void destroy()
Destroys the AnimationParams, cleaning up any object references, so we don't get memory leaks.

If the target is going away permanently, you should call destroy(). Calling MapObject.destroy() takes care of this, if the AnimationParams object is in the target's property list under the name "anima". However, if you're managing the AnimationParams yourself, or you can't call destroy() on your object, you need to call destroy() explicitly, or you'll wind up with a memory leak.