Altered character animations to separate standing image from walking
animation images. Created and made use of basic single- and multi-image implementations of the MultiFrameImage interface. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@559 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ import com.threerings.media.sprite.MultiFrameImage;
|
|||||||
import com.threerings.media.tile.TileManager;
|
import com.threerings.media.tile.TileManager;
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
|
import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
|
||||||
import com.threerings.miso.scene.xml.XMLCharacterParser;
|
import com.threerings.miso.scene.xml.XMLCharacterParser;
|
||||||
import com.threerings.miso.tile.TileUtil;
|
import com.threerings.miso.tile.TileUtil;
|
||||||
import com.threerings.miso.util.MisoUtil;
|
import com.threerings.miso.util.MisoUtil;
|
||||||
@@ -57,10 +58,10 @@ public class CharacterManager
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiFrameImage[] anims = TileUtil.getAmbulatorySpriteFrames(
|
CharacterImages imgs = TileUtil.getCharacterImages(
|
||||||
_tilemgr, tsid, info.frameCount);
|
_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.setFrameRate(info.fps);
|
||||||
sprite.setOrigin(info.origin.x, info.origin.y);
|
sprite.setOrigin(info.origin.x, info.origin.y);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
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 x the sprite x-position in pixels.
|
||||||
* @param y the sprite y-position in pixels.
|
* @param y the sprite y-position in pixels.
|
||||||
* @param anims the set of multi-frame images to use when animating
|
* @param images the images used to display the sprite when
|
||||||
* the sprite in each of the compass directions.
|
* standing or walking about.
|
||||||
*/
|
*/
|
||||||
public AmbulatorySprite (
|
public AmbulatorySprite (
|
||||||
IsoSceneViewModel model, int x, int y, MultiFrameImage[] anims)
|
IsoSceneViewModel model, int x, int y, CharacterImages images)
|
||||||
{
|
{
|
||||||
super(x, y);
|
super(x, y);
|
||||||
|
|
||||||
// keep track of these
|
// keep track of these
|
||||||
_model = model;
|
_model = model;
|
||||||
_anims = anims;
|
_images = images;
|
||||||
|
|
||||||
// give ourselves an initial orientation
|
// give ourselves an initial orientation
|
||||||
setOrientation(DIR_NORTH);
|
setOrientation(DIR_NORTH);
|
||||||
@@ -47,7 +47,11 @@ public class AmbulatorySprite extends Sprite implements Traverser
|
|||||||
super.setOrientation(orient);
|
super.setOrientation(orient);
|
||||||
|
|
||||||
// update the sprite frames to reflect the direction
|
// 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 ()
|
protected void halt ()
|
||||||
{
|
{
|
||||||
// come to a halt looking settled and at peace
|
// come to a halt looking settled and at peace
|
||||||
_frame = _frames.getFrame(_frameIdx = 0);
|
setFrames(_images.standing[_orient]);
|
||||||
invalidate();
|
|
||||||
|
|
||||||
// disable walking animation
|
// disable walking animation
|
||||||
setAnimationMode(NO_ANIMATION);
|
setAnimationMode(NO_ANIMATION);
|
||||||
@@ -213,8 +216,21 @@ public class AmbulatorySprite extends Sprite implements Traverser
|
|||||||
buf.append(", finey=").append(_finey);
|
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. */
|
/** The animation frames for the sprite facing each direction. */
|
||||||
protected MultiFrameImage[] _anims;
|
protected CharacterImages _images;
|
||||||
|
|
||||||
/** The iso scene view model. */
|
/** The iso scene view model. */
|
||||||
protected IsoSceneViewModel _model;
|
protected IsoSceneViewModel _model;
|
||||||
|
|||||||
@@ -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[];
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
package com.threerings.miso.tile;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
|
||||||
import com.threerings.media.sprite.MultiFrameImage;
|
import com.threerings.media.sprite.*;
|
||||||
import com.threerings.media.sprite.Sprite;
|
|
||||||
import com.threerings.media.tile.*;
|
import com.threerings.media.tile.*;
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
import com.threerings.miso.scene.AmbulatorySprite;
|
import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tile-related utility functions.
|
* Tile-related utility functions.
|
||||||
@@ -18,65 +17,53 @@ import com.threerings.miso.scene.AmbulatorySprite;
|
|||||||
public class TileUtil
|
public class TileUtil
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns an array of multi-frame images corresponding to the
|
* Returns a {@link CharacterImages} object containing the frames
|
||||||
* frames of animation used to render the ambulatory sprite in
|
* of animation used to render the sprite while standing or
|
||||||
* each of the directions it may face. The tileset id referenced
|
* walking in each of the directions it may face. The tileset id
|
||||||
* must contain <code>Sprite.NUM_DIRECTIONS</code> rows of tiles,
|
* referenced must contain <code>Sprite.NUM_DIRECTIONS</code> rows
|
||||||
* with each row containing <code>frameCount</code> tiles.
|
* of tiles, with each row containing first the single standing
|
||||||
|
* tile, followed by <code>frameCount</code> tiles describing the
|
||||||
|
* walking animation.
|
||||||
*
|
*
|
||||||
* @param tilemgr the tile manager to retrieve tiles from.
|
* @param tilemgr the tile manager to retrieve tiles from.
|
||||||
* @param tsid the tileset id containing the sprite tiles.
|
* @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[]
|
public static CharacterImages getCharacterImages (
|
||||||
getAmbulatorySpriteFrames (TileManager tilemgr, int tsid,
|
TileManager tilemgr, int tsid, int frameCount)
|
||||||
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 {
|
try {
|
||||||
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
|
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
|
||||||
Tile[] tiles = new Tile[frameCount];
|
|
||||||
|
|
||||||
for (int jj = 0; jj < frameCount; jj++) {
|
Image walkimgs[] = new Image[frameCount];
|
||||||
int idx = (ii * frameCount) + jj;
|
|
||||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
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) {
|
} catch (TileException te) {
|
||||||
Log.warning("Exception retrieving ambulatory sprite tiles " +
|
Log.warning("Exception retrieving character images " +
|
||||||
"[te=" + te + "].");
|
"[te=" + te + "].");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return anims;
|
return images;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user