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;
@@ -63,6 +63,10 @@ public class Sprite
updateDrawPosition();
// set default velocity
_vel = new Point(1, 1);
// initialize frame animation member data
_frameIdx = 0;
_animDelay = ANIM_NONE;
_numTicks = 0;
@@ -141,6 +145,17 @@ public class Sprite
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
* engaged in.
@@ -210,8 +225,8 @@ public class Sprite
// determine the horizontal/vertical move increments
float dist = MathUtil.distance(x, y, _dest.loc.x, _dest.loc.y);
_incx = (float)(_dest.loc.x - x) / dist;
_incy = (float)(_dest.loc.y - y) / dist;
_incx = (float)(_dest.loc.x - x) / (dist / _vel.x);
_incy = (float)(_dest.loc.y - y) / (dist / _vel.y);
// init position data used to track fractional pixels
_movex = x;
@@ -349,6 +364,9 @@ public class Sprite
/** When moving, the full path the sprite is traversing. */
protected Path _fullpath;
/** The sprite velocity when walking. */
protected Point _vel;
/** The sprite manager. */
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;
@@ -47,6 +47,7 @@ class ViewerFrame extends JFrame implements WindowListener
TileUtil.getSpriteFrames(tilemgr, TSID_CHAR);
AmbulatorySprite sprite =
new AmbulatorySprite(spritemgr, 300, 300, anims);
sprite.setVelocity(3, 3);
spritemgr.addSprite(sprite);
// create a top-level panel to manage everything