com.threerings.cast
Class CharacterSprite

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.sprite.Sprite
          extended by com.threerings.media.sprite.ImageSprite
              extended by com.threerings.cast.CharacterSprite
All Implemented Interfaces:
StandardActions, Pathable, DirectionCodes, Shape

public class CharacterSprite
extends ImageSprite
implements StandardActions

A character sprite is a sprite that animates itself while walking about in a scene.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.sprite.Sprite
Sprite.CancelledOp, Sprite.CompletedOp
 
Field Summary
protected  String _action
          The action we are currently displaying.
protected  ActionFrames _aframes
          The animation frames for the active action sequence in each orientation.
protected  CharacterManager _charmgr
          A reference to the character manager that created us.
protected  CharacterDescriptor _descrip
          A reference to the descriptor for the character that we're visualizing.
protected  String _followingPathAction
          The action to use when following a path.
protected  Rectangle _ibounds
          The bounds of the current sprite image.
protected  Point _ioff
          The offset from the upper-left of the total sprite bounds to the upper-left of the image within those bounds.
protected  String _restingAction
          The action to use when at rest.
 
Fields inherited from class com.threerings.media.sprite.ImageSprite
_animMode, _firstStamp, _frameDelay, _frameIdx, _frames, DEFAULT_FRAME_RATE, MOVEMENT_CUED, NO_ANIMATION, TIME_BASED, TIME_SEQUENTIAL
 
Fields inherited from class com.threerings.media.sprite.Sprite
_orient, _ox, _oxoff, _oy, _oyoff, _path, _pathStamp
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Fields inherited from interface com.threerings.cast.StandardActions
CROP_TYPE, SHADOW_TYPE, STANDING, WALKING
 
Fields inherited from interface com.threerings.util.DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST
 
Constructor Summary
CharacterSprite()
           
 
Method Summary
protected  void accomodateFrame(int frameIdx, int width, int height)
          Must adjust the bounds to accommodate the our new frame.
 void cancelMove()
          Cancels any path that the sprite may currently be moving along.
protected  void compositeActionFrames()
          Called to recomposite our action frames if needed.
protected  void decorateBehind(Graphics2D gfx)
          Called to paint any decorations that should appear behind the character sprite image.
protected  void decorateInFront(Graphics2D gfx)
          Called to paint any decorations that should appear in front of the character sprite image.
protected  void didInit()
          Called after this sprite has been initialized with its character descriptor and character manager.
 String getFollowingPathAction()
          Returns the action to be used when the sprite is following a path.
 String getRestingAction()
          Returns the action to be used when the sprite is at rest.
protected  void halt()
          Updates the sprite animation frame to reflect the cessation of movement and disables any further animation.
 boolean hitTest(int x, int y)
          Returns true if the sprite's bounds contain the specified point, and if there is a non-transparent pixel in the sprite's image at the specified point, false if not.
 void init(CharacterDescriptor descrip, CharacterManager charmgr)
          Initializes this character sprite with the specified character descriptor and character manager.
 void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
 void pathBeginning()
          Called by the active path when it begins.
 void pathCompleted(long timestamp)
          Called by the active path when it has completed.
protected  void sanityCheckDescrip()
          Makes it easier to track down problems with bogus character descriptors.
 void setActionSequence(String action)
          Sets the action sequence used when rendering the character, from the set of available sequences.
 void setCharacterDescriptor(CharacterDescriptor descrip)
          Reconfigures this sprite to use the specified character descriptor.
 void setFollowingPathAction(String action)
          Specifies the action to use when the sprite is following a path.
 void setOrientation(int orient)
          Sprites have an orientation in one of the eight cardinal directions: DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc.
 void setRestingAction(String action)
          Specifies the action to use when the sprite is at rest.
 void tick(long tickStamp)
          Called periodically by this media's manager to give it a chance to do its thing.
protected  boolean tickPath(long tickStamp)
          Ticks any path assigned to this sprite.
protected  void unionDecorationBounds(Rectangle bounds)
          Called by accomodateFrame(int, int, int) to give derived classes an opportunity to incorporate the bounds of any decorations that will be drawn along with this sprite.
protected  void updateActionFrames()
          Rebuilds our action frames given our current character descriptor and action sequence.
protected  void updateRenderOrigin()
          Update the coordinates at which the sprite image is drawn to reflect the sprite's current position.
 
Methods inherited from class com.threerings.media.sprite.ImageSprite
init, layout, setAnimationMode, setFrameIndex, setFrameRate, setFrames, setMirage, toString
 
Methods inherited from class com.threerings.media.sprite.Sprite
addSpriteObserver, contains, fastForward, getHeight, getOrientation, getPath, getWidth, getX, getXOffset, getY, getYOffset, inside, intersects, isMoving, move, paintPath, removeSpriteObserver, setLocation, shutdown, viewLocationDidChange
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, toString, willStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.threerings.media.util.Pathable
getBounds
 

Field Detail

_restingAction

protected String _restingAction
The action to use when at rest.


_followingPathAction

protected String _followingPathAction
The action to use when following a path.


_descrip

protected CharacterDescriptor _descrip
A reference to the descriptor for the character that we're visualizing.


_charmgr

protected CharacterManager _charmgr
A reference to the character manager that created us.


_action

protected String _action
The action we are currently displaying.


_aframes

protected ActionFrames _aframes
The animation frames for the active action sequence in each orientation.


_ioff

protected Point _ioff
The offset from the upper-left of the total sprite bounds to the upper-left of the image within those bounds.


_ibounds

protected Rectangle _ibounds
The bounds of the current sprite image.

Constructor Detail

CharacterSprite

public CharacterSprite()
Method Detail

init

public void init(CharacterDescriptor descrip,
                 CharacterManager charmgr)
Initializes this character sprite with the specified character descriptor and character manager. It will obtain animation data from the supplied character manager.


didInit

protected void didInit()
Called after this sprite has been initialized with its character descriptor and character manager. Derived classes can do post-init business here.


setCharacterDescriptor

public void setCharacterDescriptor(CharacterDescriptor descrip)
Reconfigures this sprite to use the specified character descriptor.


setRestingAction

public void setRestingAction(String action)
Specifies the action to use when the sprite is at rest. The default is STANDING.


getRestingAction

public String getRestingAction()
Returns the action to be used when the sprite is at rest. Derived classes may wish to override this method and vary the action based on external parameters (or randomly).


setFollowingPathAction

public void setFollowingPathAction(String action)
Specifies the action to use when the sprite is following a path. The default is WALKING.


getFollowingPathAction

public String getFollowingPathAction()
Returns the action to be used when the sprite is following a path. Derived classes may wish to override this method and vary the action based on external parameters (or randomly).


setActionSequence

public void setActionSequence(String action)
Sets the action sequence used when rendering the character, from the set of available sequences.


setOrientation

public void setOrientation(int orient)
Description copied from class: Sprite
Sprites have an orientation in one of the eight cardinal directions: DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc. Derived classes can choose to override this member function and select a different set of images based on their orientation, or they can ignore the orientation information.

Specified by:
setOrientation in interface Pathable
Overrides:
setOrientation in class Sprite
See Also:
DirectionCodes

hitTest

public boolean hitTest(int x,
                       int y)
Description copied from class: ImageSprite
Returns true if the sprite's bounds contain the specified point, and if there is a non-transparent pixel in the sprite's image at the specified point, false if not.

Overrides:
hitTest in class ImageSprite

tick

public void tick(long tickStamp)
Description copied from class: AbstractMedia
Called periodically by this media's manager to give it a chance to do its thing.

Overrides:
tick in class ImageSprite
Parameters:
tickStamp - a time stamp associated with this tick. Note: this is not obtained from a call to System.currentTimeMillis() and cannot be compared to timestamps obtained there from.

cancelMove

public void cancelMove()
Description copied from class: Sprite
Cancels any path that the sprite may currently be moving along.

Overrides:
cancelMove in class Sprite

pathBeginning

public void pathBeginning()
Description copied from class: Sprite
Called by the active path when it begins.

Specified by:
pathBeginning in interface Pathable
Overrides:
pathBeginning in class Sprite

pathCompleted

public void pathCompleted(long timestamp)
Description copied from class: Sprite
Called by the active path when it has completed.

Specified by:
pathCompleted in interface Pathable
Overrides:
pathCompleted in class Sprite

paint

public void paint(Graphics2D gfx)
Description copied from class: AbstractMedia
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.

Overrides:
paint in class ImageSprite

decorateBehind

protected void decorateBehind(Graphics2D gfx)
Called to paint any decorations that should appear behind the character sprite image.


decorateInFront

protected void decorateInFront(Graphics2D gfx)
Called to paint any decorations that should appear in front of the character sprite image.


updateActionFrames

protected void updateActionFrames()
Rebuilds our action frames given our current character descriptor and action sequence. This is called when either of those two things changes.


compositeActionFrames

protected final void compositeActionFrames()
Called to recomposite our action frames if needed.


sanityCheckDescrip

protected void sanityCheckDescrip()
Makes it easier to track down problems with bogus character descriptors.


tickPath

protected boolean tickPath(long tickStamp)
Description copied from class: Sprite
Ticks any path assigned to this sprite.

Overrides:
tickPath in class Sprite
Returns:
true if the path relocated the sprite as a result of this tick, false if it remained in the same position.

updateRenderOrigin

protected void updateRenderOrigin()
Description copied from class: Sprite
Update the coordinates at which the sprite image is drawn to reflect the sprite's current position.

Overrides:
updateRenderOrigin in class Sprite

accomodateFrame

protected void accomodateFrame(int frameIdx,
                               int width,
                               int height)
Description copied from class: ImageSprite
Must adjust the bounds to accommodate the our new frame. This includes changing the width and height to reflect the size of the new frame and also updating the render origin (if necessary) and calling Sprite.updateRenderOrigin() to reflect those changes in the sprite's bounds.

Overrides:
accomodateFrame in class ImageSprite
Parameters:
frameIdx - the index of our new frame.
width - the width of the new frame.
height - the height of the new frame.

unionDecorationBounds

protected void unionDecorationBounds(Rectangle bounds)
Called by accomodateFrame(int, int, int) to give derived classes an opportunity to incorporate the bounds of any decorations that will be drawn along with this sprite. The _ibounds rectangle will contain the bounds of the image that comprises the undecorated sprite. From that the position and size of decorations can be computed and unioned with the supplied bounds rectangle (most likely by using SwingUtilities.computeUnion(int, int, int, int, java.awt.Rectangle) which applies the union in place rather than creating a new rectangle).


halt

protected void halt()
Updates the sprite animation frame to reflect the cessation of movement and disables any further animation.