Allow specifying the units associated with the sprite velocity.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@331 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Sprite.java,v 1.17 2001/09/05 00:40:33 shaper Exp $
|
// $Id: Sprite.java,v 1.18 2001/09/05 21:51:43 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.media.sprite;
|
package com.threerings.media.sprite;
|
||||||
|
|
||||||
@@ -122,8 +122,10 @@ public class Sprite
|
|||||||
|
|
||||||
updateRenderOrigin();
|
updateRenderOrigin();
|
||||||
|
|
||||||
// set default velocity
|
// set default velocity and units
|
||||||
_vel = new Point(1, 1);
|
_vel = new Point(1, 1);
|
||||||
|
_velUnit = new Point(1, 1);
|
||||||
|
updateVelocity();
|
||||||
|
|
||||||
// initialize frame animation member data
|
// initialize frame animation member data
|
||||||
_frameIdx = 0;
|
_frameIdx = 0;
|
||||||
@@ -255,6 +257,29 @@ public class Sprite
|
|||||||
public void setVelocity (int vx, int vy)
|
public void setVelocity (int vx, int vy)
|
||||||
{
|
{
|
||||||
_vel.setLocation(vx, vy);
|
_vel.setLocation(vx, vy);
|
||||||
|
updateVelocity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the units upon which the sprite's velocity is based.
|
||||||
|
*
|
||||||
|
* @param ux the x-axis units.
|
||||||
|
* @param uy the y-axis units.
|
||||||
|
*/
|
||||||
|
public void setVelocityUnits (int ux, int uy)
|
||||||
|
{
|
||||||
|
_velUnit.setLocation(ux, uy);
|
||||||
|
updateVelocity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the distance the sprite moves each tick, based on the
|
||||||
|
* sprite velocity and the velocity units.
|
||||||
|
*/
|
||||||
|
protected void updateVelocity ()
|
||||||
|
{
|
||||||
|
_fracx = (_vel.x / (float)_velUnit.x);
|
||||||
|
_fracy = (_vel.y / (float)_velUnit.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -332,8 +357,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 / _vel.x);
|
_incx = (float)(_dest.loc.x - _x) / (dist / _fracx);
|
||||||
_incy = (float)(_dest.loc.y - _y) / (dist / _vel.y);
|
_incy = (float)(_dest.loc.y - _y) / (dist / _fracy);
|
||||||
|
|
||||||
// init position data used to track fractional pixels
|
// init position data used to track fractional pixels
|
||||||
_movex = _x;
|
_movex = _x;
|
||||||
@@ -516,9 +541,12 @@ public class Sprite
|
|||||||
/** When moving, the sprite position including fractional pixels. */
|
/** When moving, the sprite position including fractional pixels. */
|
||||||
protected float _movex, _movey;
|
protected float _movex, _movey;
|
||||||
|
|
||||||
/** When moving, the distance to move per tick in fractional pixels. */
|
/** When moving, the distance to move on each axis per tick. */
|
||||||
protected float _incx, _incy;
|
protected float _incx, _incy;
|
||||||
|
|
||||||
|
/** The distance to move on the straight path line per tick. */
|
||||||
|
protected float _fracx, _fracy;
|
||||||
|
|
||||||
/** The number of ticks to wait before rendering with the next image. */
|
/** The number of ticks to wait before rendering with the next image. */
|
||||||
protected int _animDelay;
|
protected int _animDelay;
|
||||||
|
|
||||||
@@ -531,6 +559,9 @@ public class Sprite
|
|||||||
/** The sprite velocity when moving. */
|
/** The sprite velocity when moving. */
|
||||||
protected Point _vel;
|
protected Point _vel;
|
||||||
|
|
||||||
|
/** The sprite velocity units. */
|
||||||
|
protected Point _velUnit;
|
||||||
|
|
||||||
/** The sprite observers observing this sprite. */
|
/** The sprite observers observing this sprite. */
|
||||||
protected ArrayList _observers;
|
protected ArrayList _observers;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user