diff --git a/src/java/com/threerings/cast/CharacterSprite.java b/src/java/com/threerings/cast/CharacterSprite.java index 0de2de987..cbdd978be 100644 --- a/src/java/com/threerings/cast/CharacterSprite.java +++ b/src/java/com/threerings/cast/CharacterSprite.java @@ -1,5 +1,5 @@ // -// $Id: CharacterSprite.java,v 1.7 2001/08/16 23:14:21 mdb Exp $ +// $Id: CharacterSprite.java,v 1.8 2001/08/21 19:40:30 mdb Exp $ package com.threerings.miso.scene; @@ -26,10 +26,9 @@ public class AmbulatorySprite extends Sprite implements Traverser * @param anims the set of multi-frame images to use when animating * the sprite in each of the compass directions. */ - public AmbulatorySprite (SpriteManager spritemgr, int x, int y, - MultiFrameImage[] anims) + public AmbulatorySprite (int x, int y, MultiFrameImage[] anims) { - super(spritemgr, x, y); + super(x, y); _anims = anims; _dir = Path.DIR_SOUTH; diff --git a/src/java/com/threerings/media/sprite/Sprite.java b/src/java/com/threerings/media/sprite/Sprite.java index ec6ea1252..1a8670633 100644 --- a/src/java/com/threerings/media/sprite/Sprite.java +++ b/src/java/com/threerings/media/sprite/Sprite.java @@ -1,5 +1,5 @@ // -// $Id: Sprite.java,v 1.13 2001/08/16 18:05:16 shaper Exp $ +// $Id: Sprite.java,v 1.14 2001/08/21 19:40:30 mdb Exp $ package com.threerings.media.sprite; @@ -25,15 +25,13 @@ public class Sprite /** * Construct a sprite object. * - * @param spritemgr the sprite manager. * @param x the sprite x-position in pixels. * @param y the sprite y-position in pixels. * @param frames the multi-frame image used to display the sprite. */ - public Sprite (SpriteManager spritemgr, int x, int y, - MultiFrameImage frames) + public Sprite (int x, int y, MultiFrameImage frames) { - init(spritemgr, x, y, frames); + init(x, y, frames); } /** @@ -41,23 +39,37 @@ public class Sprite * should be populated with a set of frames used to display it via a * subsequent call to setFrames(). * - * @param spritemgr the sprite manager. * @param x the sprite x-position in pixels. * @param y the sprite y-position in pixels. */ - public Sprite (SpriteManager spritemgr, int x, int y) + public Sprite (int x, int y) { - init(spritemgr, x, y, null); + init(x, y, null); + } + + /** + * Moves the sprite to the specified location. The location specified + * will be used as the center of the bottom edge of the sprite. + */ + public void setLocation (int x, int y) + { + // invalidate our current position + invalidate(); + // move ourselves + this.x = x; + this.y = y; + // we need to update our draw position which is based on the size + // of our current frame + updateDrawPosition(); + // invalidate our new position + invalidate(); } /** * Initialize the sprite object with its variegated parameters. */ - protected void init ( - SpriteManager spritemgr, int x, int y, MultiFrameImage frames) + protected void init (int x, int y, MultiFrameImage frames) { - _spritemgr = spritemgr; - this.x = x; this.y = y; @@ -76,6 +88,15 @@ public class Sprite invalidate(); } + /** + * Called by the sprite manager when a sprite is added to said manager + * for management. + */ + protected void setSpriteManager (SpriteManager mgr) + { + _spritemgr = mgr; + } + /** * Paint the sprite to the specified graphics context. * @@ -238,10 +259,16 @@ public class Sprite { if (_frame == null) return; - Rectangle dirty = new Rectangle( - _drawx, _drawy, _frame.getWidth(null), _frame.getHeight(null)); + if (_spritemgr != null) { + Rectangle dirty = new Rectangle( + _drawx, _drawy, + _frame.getWidth(null), _frame.getHeight(null)); + _spritemgr.addDirtyRect(dirty); - _spritemgr.addDirtyRect(dirty); + } else { + Log.warning("Was invalidated but have no sprite manager " + + this + "."); + } } /** diff --git a/src/java/com/threerings/media/sprite/SpriteManager.java b/src/java/com/threerings/media/sprite/SpriteManager.java index d34053a4f..97fb31cbb 100644 --- a/src/java/com/threerings/media/sprite/SpriteManager.java +++ b/src/java/com/threerings/media/sprite/SpriteManager.java @@ -1,5 +1,5 @@ // -// $Id: SpriteManager.java,v 1.8 2001/08/21 00:58:36 mdb Exp $ +// $Id: SpriteManager.java,v 1.9 2001/08/21 19:40:30 mdb Exp $ package com.threerings.media.sprite; @@ -39,7 +39,12 @@ public class SpriteManager */ public void addSprite (Sprite sprite) { + // let the sprite know about us + sprite.setSpriteManager(this); + // add the sprite to our list _sprites.add(sprite); + // and invalidate the sprite's original position + sprite.invalidate(); } /** @@ -50,7 +55,12 @@ public class SpriteManager */ public void removeSprite (Sprite sprite) { + // invalidate the current sprite position + sprite.invalidate(); + // remove the sprite from our list _sprites.remove(sprite); + // clear out our manager reference + sprite.setSpriteManager(null); } /**