Cleaned up some sprite business: better documented various things, changed

local member names to reflect their actual functionality, flipped the sign
of the origin offset so that it's an offset rather than a negative offset.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1512 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-06-20 21:42:53 +00:00
parent 29cd8ec051
commit 1f80cf9805
3 changed files with 49 additions and 40 deletions
@@ -1,5 +1,5 @@
//
// $Id: CharacterSprite.java,v 1.34 2002/06/19 23:31:57 mdb Exp $
// $Id: CharacterSprite.java,v 1.35 2002/06/20 21:42:53 mdb Exp $
package com.threerings.cast;
@@ -146,13 +146,17 @@ public class CharacterSprite extends ImageSprite
// }
// documentation inherited
protected void accomodateFrame (int width, int height)
protected void accomodateFrame (int frameIdx, int width, int height)
{
super.accomodateFrame(width, height);
// this will update our width and height
super.accomodateFrame(frameIdx, width, height);
// we need to update the render offset for this frame
_rxoff = -_aframes.getXOrigin(_orient, _frameIdx);
_ryoff = -_aframes.getYOrigin(_orient, _frameIdx);
// we now need to update the render offset for this frame
_oxoff = _aframes.getXOrigin(_orient, frameIdx);
_oyoff = _aframes.getYOrigin(_orient, frameIdx);
// and cause those changes to be reflected in our bounds
updateRenderOrigin();
}
// documentation inherited
@@ -1,5 +1,5 @@
//
// $Id: ImageSprite.java,v 1.8 2002/06/19 23:30:06 mdb Exp $
// $Id: ImageSprite.java,v 1.9 2002/06/20 21:42:53 mdb Exp $
package com.threerings.media.sprite;
@@ -181,12 +181,9 @@ public class ImageSprite extends Sprite
Rectangle dirty = new Rectangle(_bounds);
// determine our drawing offsets and rendered rectangle size
accomodateFrame(_frames.getWidth(_frameIdx),
accomodateFrame(_frameIdx, _frames.getWidth(_frameIdx),
_frames.getHeight(_frameIdx));
// account for any new render offsets
updateRenderOrigin();
// add our new bounds
dirty.add(_bounds);
@@ -197,13 +194,17 @@ public class ImageSprite extends Sprite
}
/**
* Must adjust the bounds to accomodate the new image. Called when a
* new image has been set for this image sprite. If a derived class is
* going to expand the bounds beyond the bounds of the image frame, it
* will need to override this method and adjust bounds accordingly for
* the new frame (which can be null).
* 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
* sprite's bounds.
*
* @param frameIdx the index of our new frame.
* @param width the width of the new frame.
* @param height the height of the new frame.
*/
protected void accomodateFrame (int width, int height)
protected void accomodateFrame (int frameIdx, int width, int height)
{
_bounds.width = width;
_bounds.height = height;
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.48 2002/06/19 23:30:06 mdb Exp $
// $Id: Sprite.java,v 1.49 2002/06/20 21:42:53 mdb Exp $
package com.threerings.media.sprite;
@@ -40,8 +40,8 @@ public abstract class Sprite
*/
public Sprite (int x, int y)
{
_x = x;
_y = y;
_ox = x;
_oy = y;
}
/**
@@ -72,7 +72,7 @@ public abstract class Sprite
*/
public int getX ()
{
return _x;
return _ox;
}
/**
@@ -82,7 +82,7 @@ public abstract class Sprite
*/
public int getY ()
{
return _y;
return _oy;
}
/**
@@ -165,11 +165,11 @@ public abstract class Sprite
Rectangle dirty = new Rectangle(_bounds);
// move ourselves
_x = x;
_y = y;
_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();
// grow the dirty rectangle to incorporate our new bounds and pass
@@ -233,7 +233,7 @@ public abstract class Sprite
*/
public boolean inside (Shape shape)
{
return shape.contains(_x, _y);
return shape.contains(_ox, _oy);
}
/**
@@ -357,9 +357,9 @@ public abstract class Sprite
*/
protected void updateRenderOrigin ()
{
// our render origin may differ from our location
_bounds.x = _x + _rxoff;
_bounds.y = _y + _ryoff;
// our bounds origin may differ from the sprite's origin
_bounds.x = _ox - _oxoff;
_bounds.y = _oy - _oyoff;
}
/**
@@ -417,22 +417,26 @@ public abstract class Sprite
*/
protected void toString (StringBuffer buf)
{
buf.append("x=").append(_x);
buf.append(", y=").append(_y);
buf.append(", rxoff=").append(_rxoff);
buf.append(", ryoff=").append(_ryoff);
buf.append("ox=").append(_ox);
buf.append(", oy=").append(_oy);
buf.append(", oxoff=").append(_oxoff);
buf.append(", oyoff=").append(_oyoff);
}
/** The sprite manager. */
protected SpriteManager _spritemgr;
/** The location of the sprite in pixel coordinates. */
protected int _x, _y;
/** The location of the sprite's origin in pixel coordinates. If the
* sprite positions itself via a hotspot that is not the upper left
* coordinate of the sprite's bounds, the offset to the hotspot should
* be maintained in {@link #_oxoff} and {@link #_oyoff}. */
protected int _ox, _oy;
/** The offsets from our location to our rendered origin. Derived
* classes may wish to set these values if the sprite's upper left
* corner should not be coincident with its location. */
protected int _rxoff, _ryoff;
/** The offsets from our upper left coordinate to our origin (or hot
* spot). Derived classes will need to update these values if the
* sprite's origin is not coincident with the upper left coordinate of
* its bounds. */
protected int _oxoff, _oyoff;
/** Our rendered bounds in pixel coordinates. */
protected Rectangle _bounds = new Rectangle();