Allow setting the sprite velocity to be used when following a path.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@262 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-15 22:48:41 +00:00
parent cff9a1fbef
commit 8520b2e84b
2 changed files with 23 additions and 4 deletions
@@ -1,5 +1,5 @@
// //
// $Id: Sprite.java,v 1.11 2001/08/15 22:06:21 shaper Exp $ // $Id: Sprite.java,v 1.12 2001/08/15 22:48:41 shaper Exp $
package com.threerings.media.sprite; package com.threerings.media.sprite;
@@ -63,6 +63,10 @@ public class Sprite
updateDrawPosition(); updateDrawPosition();
// set default velocity
_vel = new Point(1, 1);
// initialize frame animation member data
_frameIdx = 0; _frameIdx = 0;
_animDelay = ANIM_NONE; _animDelay = ANIM_NONE;
_numTicks = 0; _numTicks = 0;
@@ -141,6 +145,17 @@ public class Sprite
invalidate(); invalidate();
} }
/**
* Set the sprite's velocity when walking.
*
* @param vx the x-axis velocity.
* @param vy the y-axis velocity.
*/
public void setVelocity (int vx, int vy)
{
_vel.setLocation(vx, vy);
}
/** /**
* Stop the sprite from any movement along a path it may be * Stop the sprite from any movement along a path it may be
* engaged in. * engaged in.
@@ -210,8 +225,8 @@ public class Sprite
// determine the horizontal/vertical move increments // determine the horizontal/vertical move increments
float dist = MathUtil.distance(x, y, _dest.loc.x, _dest.loc.y); float dist = MathUtil.distance(x, y, _dest.loc.x, _dest.loc.y);
_incx = (float)(_dest.loc.x - x) / dist; _incx = (float)(_dest.loc.x - x) / (dist / _vel.x);
_incy = (float)(_dest.loc.y - y) / dist; _incy = (float)(_dest.loc.y - y) / (dist / _vel.y);
// init position data used to track fractional pixels // init position data used to track fractional pixels
_movex = x; _movex = x;
@@ -349,6 +364,9 @@ public class Sprite
/** When moving, the full path the sprite is traversing. */ /** When moving, the full path the sprite is traversing. */
protected Path _fullpath; protected Path _fullpath;
/** The sprite velocity when walking. */
protected Point _vel;
/** The sprite manager. */ /** The sprite manager. */
protected SpriteManager _spritemgr; protected SpriteManager _spritemgr;
} }
@@ -1,5 +1,5 @@
// //
// $Id: ViewerFrame.java,v 1.12 2001/08/15 02:30:28 shaper Exp $ // $Id: ViewerFrame.java,v 1.13 2001/08/15 22:48:41 shaper Exp $
package com.threerings.miso.viewer; package com.threerings.miso.viewer;
@@ -47,6 +47,7 @@ class ViewerFrame extends JFrame implements WindowListener
TileUtil.getSpriteFrames(tilemgr, TSID_CHAR); TileUtil.getSpriteFrames(tilemgr, TSID_CHAR);
AmbulatorySprite sprite = AmbulatorySprite sprite =
new AmbulatorySprite(spritemgr, 300, 300, anims); new AmbulatorySprite(spritemgr, 300, 300, anims);
sprite.setVelocity(3, 3);
spritemgr.addSprite(sprite); spritemgr.addSprite(sprite);
// create a top-level panel to manage everything // create a top-level panel to manage everything