- Initialize our timestmap in willStart() (which postdates the original
creation of this class). - Track when all the sparks have moved outside the bounds of the animation and end it then. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3649 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -126,24 +126,22 @@ public class SparkAnimation extends Animation
|
|||||||
return (RandomUtil.getInt(2) == 0) ? -1 : 1;
|
return (RandomUtil.getInt(2) == 0) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
protected void willStart (long stamp)
|
||||||
|
{
|
||||||
|
super.willStart(stamp);
|
||||||
|
_start = stamp;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void fastForward (long timeDelta)
|
public void fastForward (long timeDelta)
|
||||||
{
|
{
|
||||||
if (_start > 0) {
|
_start += timeDelta;
|
||||||
_start += timeDelta;
|
|
||||||
_end += timeDelta;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void tick (long timestamp)
|
public void tick (long timestamp)
|
||||||
{
|
{
|
||||||
if (_start == 0) {
|
|
||||||
// initialize our starting time
|
|
||||||
_start = timestamp;
|
|
||||||
_end = _start + _delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
// figure out the distance the chunks have travelled
|
// figure out the distance the chunks have travelled
|
||||||
long msecs = Math.max(timestamp - _start, 0);
|
long msecs = Math.max(timestamp - _start, 0);
|
||||||
long msecsSq = msecs * msecs;
|
long msecsSq = msecs * msecs;
|
||||||
@@ -155,6 +153,9 @@ public class SparkAnimation extends Animation
|
|||||||
_comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha);
|
_comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assume all sparks have moved outside the bounds
|
||||||
|
boolean allOutside = true;
|
||||||
|
|
||||||
// move all sparks and check whether any remain to be animated
|
// move all sparks and check whether any remain to be animated
|
||||||
for (int ii = 0; ii < _icount; ii++) {
|
for (int ii = 0; ii < _icount; ii++) {
|
||||||
// determine the travel distance
|
// determine the travel distance
|
||||||
@@ -166,10 +167,17 @@ public class SparkAnimation extends Animation
|
|||||||
// update the position
|
// update the position
|
||||||
_xpos[ii] = _ox[ii] + xtrav;
|
_xpos[ii] = _ox[ii] + xtrav;
|
||||||
_ypos[ii] = _oy[ii] + ytrav;
|
_ypos[ii] = _oy[ii] + ytrav;
|
||||||
|
|
||||||
|
// check to see if any are still in. Stop looking
|
||||||
|
// when we find one
|
||||||
|
if (allOutside && _bounds.intersects(_xpos[ii], _ypos[ii],
|
||||||
|
_images[ii].getWidth(), _images[ii].getHeight())) {
|
||||||
|
allOutside = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note whether we're finished
|
// note whether we're finished
|
||||||
_finished = (timestamp >= _end);
|
_finished = allOutside || (msecs >= _delay);
|
||||||
|
|
||||||
// dirty ourselves
|
// dirty ourselves
|
||||||
// TODO: only do this if at least one spark actually moved
|
// TODO: only do this if at least one spark actually moved
|
||||||
@@ -235,9 +243,6 @@ public class SparkAnimation extends Animation
|
|||||||
/** The starting animation time. */
|
/** The starting animation time. */
|
||||||
protected long _start;
|
protected long _start;
|
||||||
|
|
||||||
/** The ending animation time. */
|
|
||||||
protected long _end;
|
|
||||||
|
|
||||||
/** Whether or not we should fade the sparks out. */
|
/** Whether or not we should fade the sparks out. */
|
||||||
protected boolean _fade;
|
protected boolean _fade;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user