diff --git a/src/java/com/threerings/cast/CharacterManager.java b/src/java/com/threerings/cast/CharacterManager.java
index 42f7a6655..6e619ed00 100644
--- a/src/java/com/threerings/cast/CharacterManager.java
+++ b/src/java/com/threerings/cast/CharacterManager.java
@@ -1,5 +1,5 @@
//
-// $Id: CharacterManager.java,v 1.3 2001/10/24 00:55:08 shaper Exp $
+// $Id: CharacterManager.java,v 1.4 2001/10/25 18:06:17 shaper Exp $
package com.threerings.miso.scene;
@@ -13,6 +13,7 @@ import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log;
+import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
import com.threerings.miso.scene.xml.XMLCharacterParser;
import com.threerings.miso.tile.TileUtil;
import com.threerings.miso.util.MisoUtil;
@@ -57,10 +58,10 @@ public class CharacterManager
return null;
}
- MultiFrameImage[] anims = TileUtil.getAmbulatorySpriteFrames(
+ CharacterImages imgs = TileUtil.getCharacterImages(
_tilemgr, tsid, info.frameCount);
- AmbulatorySprite sprite = new AmbulatorySprite(_model, 0, 0, anims);
+ AmbulatorySprite sprite = new AmbulatorySprite(_model, 0, 0, imgs);
sprite.setFrameRate(info.fps);
sprite.setOrigin(info.origin.x, info.origin.y);
diff --git a/src/java/com/threerings/cast/CharacterSprite.java b/src/java/com/threerings/cast/CharacterSprite.java
index bbda2b412..fc60cdbfd 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.14 2001/10/24 00:55:08 shaper Exp $
+// $Id: CharacterSprite.java,v 1.15 2001/10/25 18:06:17 shaper Exp $
package com.threerings.miso.scene;
@@ -25,17 +25,17 @@ public class AmbulatorySprite extends Sprite implements Traverser
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
- * @param anims the set of multi-frame images to use when animating
- * the sprite in each of the compass directions.
+ * @param images the images used to display the sprite when
+ * standing or walking about.
*/
public AmbulatorySprite (
- IsoSceneViewModel model, int x, int y, MultiFrameImage[] anims)
+ IsoSceneViewModel model, int x, int y, CharacterImages images)
{
super(x, y);
// keep track of these
_model = model;
- _anims = anims;
+ _images = images;
// give ourselves an initial orientation
setOrientation(DIR_NORTH);
@@ -47,7 +47,11 @@ public class AmbulatorySprite extends Sprite implements Traverser
super.setOrientation(orient);
// update the sprite frames to reflect the direction
- setFrames(_anims[_orient]);
+ if (_path == null) {
+ setFrames(_images.standing[_orient]);
+ } else {
+ setFrames(_images.walking[_orient]);
+ }
}
/**
@@ -106,8 +110,7 @@ public class AmbulatorySprite extends Sprite implements Traverser
protected void halt ()
{
// come to a halt looking settled and at peace
- _frame = _frames.getFrame(_frameIdx = 0);
- invalidate();
+ setFrames(_images.standing[_orient]);
// disable walking animation
setAnimationMode(NO_ANIMATION);
@@ -213,8 +216,21 @@ public class AmbulatorySprite extends Sprite implements Traverser
buf.append(", finey=").append(_finey);
}
+ /**
+ * A class to hold the images that are used to display the sprite
+ * while walking about.
+ */
+ public static class CharacterImages
+ {
+ /** The images of the sprite standing at rest in each orientation. */
+ public MultiFrameImage standing[];
+
+ /** The images of the sprite walking in each orientation. */
+ public MultiFrameImage walking[];
+ }
+
/** The animation frames for the sprite facing each direction. */
- protected MultiFrameImage[] _anims;
+ protected CharacterImages _images;
/** The iso scene view model. */
protected IsoSceneViewModel _model;
diff --git a/src/java/com/threerings/media/util/MultiFrameImageImpl.java b/src/java/com/threerings/media/util/MultiFrameImageImpl.java
new file mode 100644
index 000000000..75f83b3b7
--- /dev/null
+++ b/src/java/com/threerings/media/util/MultiFrameImageImpl.java
@@ -0,0 +1,37 @@
+//
+// $Id: MultiFrameImageImpl.java,v 1.1 2001/10/25 18:06:17 shaper Exp $
+
+package com.threerings.media.sprite;
+
+import java.awt.Image;
+
+/**
+ * A basic implementation of the {@link MultiFrameImage} interface
+ * intended to facilitate the creation of sprites whose display frames
+ * consist of multiple image objects.
+ */
+public class MultiFrameImageImpl implements MultiFrameImage
+{
+ /**
+ * Constructs a multiple frame image object.
+ */
+ public MultiFrameImageImpl (Image imgs[])
+ {
+ _imgs = imgs;
+ }
+
+ // documentation inherited
+ public int getFrameCount ()
+ {
+ return _imgs.length;
+ }
+
+ // documentation inherited
+ public Image getFrame (int index)
+ {
+ return _imgs[index];
+ }
+
+ /** The frame images. */
+ protected Image _imgs[];
+}
diff --git a/src/java/com/threerings/media/util/SingleFrameImageImpl.java b/src/java/com/threerings/media/util/SingleFrameImageImpl.java
new file mode 100644
index 000000000..65e6a7033
--- /dev/null
+++ b/src/java/com/threerings/media/util/SingleFrameImageImpl.java
@@ -0,0 +1,38 @@
+//
+// $Id: SingleFrameImageImpl.java,v 1.1 2001/10/25 18:06:17 shaper Exp $
+
+package com.threerings.media.sprite;
+
+import java.awt.Image;
+
+/**
+ * The single frame image class is a basic implementation of the
+ * {@link MultiFrameImage} interface intended to facilitate the
+ * creation of sprites whose display frames consist of only a single
+ * image.
+ */
+public class SingleFrameImageImpl implements MultiFrameImage
+{
+ /**
+ * Constructs a single frame image object.
+ */
+ public SingleFrameImageImpl (Image img)
+ {
+ _img = img;
+ }
+
+ // documentation inherited
+ public int getFrameCount ()
+ {
+ return 1;
+ }
+
+ // documentation inherited
+ public Image getFrame (int index)
+ {
+ return _img;
+ }
+
+ /** The frame image. */
+ protected Image _img;
+}
diff --git a/src/java/com/threerings/miso/tile/TileUtil.java b/src/java/com/threerings/miso/tile/TileUtil.java
index 3b2bd3a6c..fbba88b57 100644
--- a/src/java/com/threerings/miso/tile/TileUtil.java
+++ b/src/java/com/threerings/miso/tile/TileUtil.java
@@ -1,16 +1,15 @@
//
-// $Id: TileUtil.java,v 1.7 2001/10/15 23:53:43 shaper Exp $
+// $Id: TileUtil.java,v 1.8 2001/10/25 18:06:17 shaper Exp $
package com.threerings.miso.tile;
import java.awt.Image;
-import com.threerings.media.sprite.MultiFrameImage;
-import com.threerings.media.sprite.Sprite;
+import com.threerings.media.sprite.*;
import com.threerings.media.tile.*;
import com.threerings.miso.Log;
-import com.threerings.miso.scene.AmbulatorySprite;
+import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
/**
* Tile-related utility functions.
@@ -18,65 +17,53 @@ import com.threerings.miso.scene.AmbulatorySprite;
public class TileUtil
{
/**
- * Returns an array of multi-frame images corresponding to the
- * frames of animation used to render the ambulatory sprite in
- * each of the directions it may face. The tileset id referenced
- * must contain Sprite.NUM_DIRECTIONS rows of tiles,
- * with each row containing frameCount tiles.
+ * Returns a {@link CharacterImages} object containing the frames
+ * of animation used to render the sprite while standing or
+ * walking in each of the directions it may face. The tileset id
+ * referenced must contain Sprite.NUM_DIRECTIONS rows
+ * of tiles, with each row containing first the single standing
+ * tile, followed by frameCount tiles describing the
+ * walking animation.
*
* @param tilemgr the tile manager to retrieve tiles from.
* @param tsid the tileset id containing the sprite tiles.
+ * @param frameCount the number of walking frames of animation.
*
- * @return the array of multi-frame sprite images.
+ * @return the ambulatory images object.
*/
- public static MultiFrameImage[]
- getAmbulatorySpriteFrames (TileManager tilemgr, int tsid,
- int frameCount)
+ public static CharacterImages getCharacterImages (
+ TileManager tilemgr, int tsid, int frameCount)
{
- MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
+ CharacterImages images = new CharacterImages();
+ images.standing = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
+ images.walking = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
try {
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
- Tile[] tiles = new Tile[frameCount];
- for (int jj = 0; jj < frameCount; jj++) {
- int idx = (ii * frameCount) + jj;
- tiles[jj] = tilemgr.getTile(tsid, idx);
+ Image walkimgs[] = new Image[frameCount];
+
+ int rowcount = frameCount + 1;
+ for (int jj = 0; jj < rowcount; jj++) {
+ int idx = (ii * rowcount) + jj;
+
+ Image img = tilemgr.getTile(tsid, idx).img;
+ if (jj == 0) {
+ images.standing[ii] = new SingleFrameImageImpl(img);
+ } else {
+ walkimgs[jj - 1] = img;
+ }
}
- anims[ii] = new MultiTileImage(tiles);
+ images.walking[ii] = new MultiFrameImageImpl(walkimgs);
}
} catch (TileException te) {
- Log.warning("Exception retrieving ambulatory sprite tiles " +
+ Log.warning("Exception retrieving character images " +
"[te=" + te + "].");
return null;
}
- return anims;
- }
-
- /**
- * A class that treats an array of tiles as source images for a
- * multi-frame animation to be used by the sprite engine.
- */
- protected static class MultiTileImage implements MultiFrameImage
- {
- public MultiTileImage (Tile[] tiles)
- {
- _tiles = tiles;
- }
-
- public int getFrameCount ()
- {
- return _tiles.length;
- }
-
- public Image getFrame (int index)
- {
- return _tiles[index].img;
- }
-
- protected Tile[] _tiles;
+ return images;
}
}