More import cleanups to go with r662, along with a little bit of foreaching, widening, etc.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@664 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -24,6 +24,7 @@ package com.threerings.media.sprite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import com.threerings.media.AbstractMedia;
|
||||
import com.threerings.media.image.Mirage;
|
||||
import com.threerings.media.util.MultiFrameImage;
|
||||
import com.threerings.media.util.SingleFrameImageImpl;
|
||||
@@ -55,11 +56,10 @@ public class ImageSprite extends Sprite
|
||||
public static final int TIME_SEQUENTIAL = 3;
|
||||
|
||||
/**
|
||||
* Constructs an image sprite without any associated frames and with
|
||||
* an invalid default initial location. The sprite should be populated
|
||||
* with a set of frames used to display it via a subsequent call to
|
||||
* {@link #setFrames}, and its location updated with {@link
|
||||
* #setLocation}.
|
||||
* Constructs an image sprite without any associated frames and with an invalid default initial
|
||||
* location. The sprite should be populated with a set of frames used to display it via a
|
||||
* subsequent call to {@link #setFrames}, and its location updated with
|
||||
* {@link AbstractMedia#setLocation}.
|
||||
*/
|
||||
public ImageSprite ()
|
||||
{
|
||||
@@ -81,8 +81,7 @@ public class ImageSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an image sprite that will display the supplied single
|
||||
* image when rendering itself.
|
||||
* Constructs an image sprite that will display the supplied single image when rendering itself.
|
||||
*/
|
||||
public ImageSprite (Mirage image)
|
||||
{
|
||||
@@ -94,22 +93,19 @@ public class ImageSprite extends Sprite
|
||||
{
|
||||
super.init();
|
||||
|
||||
// now that we have our sprite manager, we can lay ourselves out
|
||||
// and initialize our frames
|
||||
// now that we have our sprite manager, we can lay ourselves out and initialize our frames
|
||||
layout();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean hitTest (int x, int y)
|
||||
{
|
||||
// first check to see that we're in the sprite's bounds and that
|
||||
// we've got a frame image (if we've got no image, there's nothing
|
||||
// to be hit)
|
||||
// first check to see that we're in the sprite's bounds and that we've got a frame image
|
||||
// (if we've got no image, there's nothing to be hit)
|
||||
if (!super.hitTest(x, y) || _frames == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -136,9 +132,8 @@ public class ImageSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of frames per second desired for the sprite
|
||||
* animation. This is only used when the animation mode is
|
||||
* <code>TIME_BASED</code>.
|
||||
* Sets the number of frames per second desired for the sprite animation. This is only used
|
||||
* when the animation mode is <code>TIME_BASED</code>.
|
||||
*
|
||||
* @param fps the desired frames per second.
|
||||
*/
|
||||
@@ -163,13 +158,11 @@ public class ImageSprite extends Sprite
|
||||
public void setFrames (MultiFrameImage frames)
|
||||
{
|
||||
if (frames == null) {
|
||||
// Log.warning("Someone set up us the null frames! " +
|
||||
// "[sprite=" + this + "].");
|
||||
// log.warning("Someone set up us the null frames!", "sprite", this);
|
||||
return;
|
||||
}
|
||||
|
||||
// if these are the same frames we already had, no need to do a
|
||||
// bunch of pointless business
|
||||
// if these are the same frames we already had, no need to do a bunch of pointless business
|
||||
if (frames == _frames) {
|
||||
return;
|
||||
}
|
||||
@@ -181,8 +174,7 @@ public class ImageSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs this sprite to lay out its current frame and any
|
||||
* accoutrements.
|
||||
* Instructs this sprite to lay out its current frame and any accoutrements.
|
||||
*/
|
||||
public void layout ()
|
||||
{
|
||||
@@ -224,10 +216,9 @@ public class ImageSprite extends Sprite
|
||||
}
|
||||
|
||||
/**
|
||||
* Must adjust the bounds to accomodate 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 {@link #updateRenderOrigin} to reflect those changes in the
|
||||
* 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 {@link Sprite#updateRenderOrigin} to reflect those changes in the
|
||||
* sprite's bounds.
|
||||
*
|
||||
* @param frameIdx the index of our new frame.
|
||||
@@ -266,11 +257,11 @@ public class ImageSprite extends Sprite
|
||||
if (_frames == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int fcount = _frames.getFrameCount();
|
||||
boolean moved = false;
|
||||
|
||||
// move the sprite along toward its destination, if any
|
||||
// move the sprite along toward its destination, if any
|
||||
moved = tickPath(timestamp);
|
||||
|
||||
// increment the display image if performing image animation
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.threerings.media.sprite;
|
||||
|
||||
import com.threerings.media.FrameManager;
|
||||
import com.threerings.media.util.Path;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ public interface PathObserver
|
||||
* @param sprite the sprite that completed its path.
|
||||
* @param path the path that was completed.
|
||||
* @param when the tick stamp of the media tick on which the path was
|
||||
* completed (see {@link SpriteManager#tick}) (this may not be in the
|
||||
* completed (see {@link FrameManager#tick}) (this may not be in the
|
||||
* same time domain as {@link System#currentTimeMillis}).
|
||||
*/
|
||||
public void pathCompleted (Sprite sprite, Path path, long when);
|
||||
|
||||
@@ -34,20 +34,18 @@ import com.threerings.media.util.Path;
|
||||
import com.threerings.media.util.Pathable;
|
||||
|
||||
/**
|
||||
* The sprite class represents a single moveable object in an animated
|
||||
* view. A sprite has a position and orientation within the view, and can
|
||||
* be moved along a path.
|
||||
* The sprite class represents a single moveable object in an animated view. A sprite has a
|
||||
* position and orientation within the view, and can be moved along a path.
|
||||
*/
|
||||
public abstract class Sprite extends AbstractMedia
|
||||
implements DirectionCodes, Pathable
|
||||
{
|
||||
/**
|
||||
* Constructs a sprite with an initially invalid location. Because
|
||||
* sprite derived classes generally want to get in on the business
|
||||
* when a sprite's location is set, it is not safe to do so in the
|
||||
* constructor because their derived methods will be called before
|
||||
* their constructor has been called. Thus a sprite should be fully
|
||||
* constructed and <em>then</em> its location should be set.
|
||||
* Constructs a sprite with an initially invalid location. Because sprite derived classes
|
||||
* generally want to get in on the business when a sprite's location is set, it is not safe to
|
||||
* do so in the constructor because their derived methods will be called before their
|
||||
* constructor has been called. Thus a sprite should be fully constructed and <em>then</em> its
|
||||
* location should be set.
|
||||
*/
|
||||
public Sprite ()
|
||||
{
|
||||
@@ -55,12 +53,11 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sprite with the supplied dimensions. Because
|
||||
* sprite derived classes generally want to get in on the business
|
||||
* when a sprite's location is set, it is not safe to do so in the
|
||||
* constructor because their derived methods will be called before
|
||||
* their constructor has been called. Thus a sprite should be fully
|
||||
* constructed and <em>then</em> its location should be set.
|
||||
* Constructs a sprite with the supplied dimensions. Because sprite derived classes generally
|
||||
* want to get in on the business when a sprite's location is set, it is not safe to do so in
|
||||
* the constructor because their derived methods will be called before their constructor has
|
||||
* been called. Thus a sprite should be fully constructed and <em>then</em> its location should
|
||||
* be set.
|
||||
*/
|
||||
public Sprite (int width, int height)
|
||||
{
|
||||
@@ -68,9 +65,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's x position in screen coordinates. This is the
|
||||
* x coordinate of the sprite's origin, not the upper left of its
|
||||
* bounds.
|
||||
* Returns the sprite's x position in screen coordinates. This is the x coordinate of the
|
||||
* sprite's origin, not the upper left of its bounds.
|
||||
*/
|
||||
public int getX ()
|
||||
{
|
||||
@@ -78,9 +74,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's y position in screen coordinates. This is the
|
||||
* y coordinate of the sprite's origin, not the upper left of its
|
||||
* bounds.
|
||||
* Returns the sprite's y position in screen coordinates. This is the y coordinate of the
|
||||
* sprite's origin, not the upper left of its bounds.
|
||||
*/
|
||||
public int getY ()
|
||||
{
|
||||
@@ -88,8 +83,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset to the sprite's origin from the upper-left of
|
||||
* the sprite's image.
|
||||
* Returns the offset to the sprite's origin from the upper-left of the sprite's image.
|
||||
*/
|
||||
public int getXOffset ()
|
||||
{
|
||||
@@ -97,8 +91,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset to the sprite's origin from the upper-left of
|
||||
* the sprite's image.
|
||||
* Returns the offset to the sprite's origin from the upper-left of the sprite's image.
|
||||
*/
|
||||
public int getYOffset ()
|
||||
{
|
||||
@@ -122,11 +115,10 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprites have an orientation in one of the eight cardinal
|
||||
* directions: <code>NORTH</code>, <code>NORTHEAST</code>, 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.
|
||||
* Sprites have an orientation in one of the eight cardinal directions: <code>NORTH</code>,
|
||||
* <code>NORTHEAST</code>, 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.
|
||||
*
|
||||
* @see DirectionCodes
|
||||
*/
|
||||
@@ -136,8 +128,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's orientation as one of the eight cardinal
|
||||
* directions: <code>NORTH</code>, <code>NORTHEAST</code>, etc.
|
||||
* Returns the sprite's orientation as one of the eight cardinal directions:
|
||||
* <code>NORTH</code>, <code>NORTHEAST</code>, etc.
|
||||
*
|
||||
* @see DirectionCodes
|
||||
*/
|
||||
@@ -160,8 +152,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
_ox = x;
|
||||
_oy = y;
|
||||
|
||||
// we need to update our draw position which is based on the size
|
||||
// of our current bounds
|
||||
// we need to update our draw position which is based on the size of our current bounds
|
||||
updateRenderOrigin();
|
||||
|
||||
// this method will invalidate our old and new bounds efficiently
|
||||
@@ -187,8 +178,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the sprite's bounds contain the specified point,
|
||||
* false if not.
|
||||
* Returns true if the sprite's bounds contain the specified point, false if not.
|
||||
*/
|
||||
public boolean contains (int x, int y)
|
||||
{
|
||||
@@ -196,8 +186,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the sprite's bounds contain the specified point,
|
||||
* false if not.
|
||||
* Returns true if the sprite's bounds contain the specified point, false if not.
|
||||
*/
|
||||
public boolean hitTest (int x, int y)
|
||||
{
|
||||
@@ -205,8 +194,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the sprite is inside the given shape in pixel
|
||||
* coordinates.
|
||||
* Returns whether the sprite is inside the given shape in pixel coordinates.
|
||||
*/
|
||||
public boolean inside (Shape shape)
|
||||
{
|
||||
@@ -214,8 +202,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the sprite's drawn rectangle intersects the given
|
||||
* shape in pixel coordinates.
|
||||
* Returns whether the sprite's drawn rectangle intersects the given shape in pixel coordinates.
|
||||
*/
|
||||
public boolean intersects (Shape shape)
|
||||
{
|
||||
@@ -223,8 +210,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this sprite is currently following a path, false if
|
||||
* it is not.
|
||||
* Returns true if this sprite is currently following a path, false if it is not.
|
||||
*/
|
||||
public boolean isMoving ()
|
||||
{
|
||||
@@ -232,9 +218,9 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sprite's active path and start moving it along its merry
|
||||
* way. If the sprite is already moving along a previous path the old
|
||||
* path will be lost and the new path will begin to be traversed.
|
||||
* Set the sprite's active path and start moving it along its merry way. If the sprite is
|
||||
* already moving along a previous path the old path will be lost and the new path will begin
|
||||
* to be traversed.
|
||||
*
|
||||
* @param path the path to follow.
|
||||
*/
|
||||
@@ -266,8 +252,7 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path being followed by this sprite or null if the
|
||||
* sprite is not following a path.
|
||||
* Returns the path being followed by this sprite or null if the sprite is not following a path.
|
||||
*/
|
||||
public Path getPath ()
|
||||
{
|
||||
@@ -318,9 +303,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
_path.init(this, _pathStamp = tickStamp);
|
||||
}
|
||||
|
||||
// it's possible that as a result of init() the path completed and
|
||||
// removed itself with a call to pathCompleted(), so we have to be
|
||||
// careful here
|
||||
// it's possible that as a result of init() the path completed and removed itself with a
|
||||
// call to pathCompleted(), so we have to be careful here
|
||||
return (_path == null) ? true : _path.tick(this, tickStamp);
|
||||
}
|
||||
|
||||
@@ -334,8 +318,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the coordinates at which the sprite image is drawn to
|
||||
* reflect the sprite's current position.
|
||||
* Update the coordinates at which the sprite image is drawn to reflect the sprite's current
|
||||
* position.
|
||||
*/
|
||||
protected void updateRenderOrigin ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user