From 84361f9f9bb56a820950179a18ed1c7d56ec7ebb Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 14 Jul 2005 01:37:34 +0000 Subject: [PATCH] - 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 --- .../media/animation/SparkAnimation.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/java/com/threerings/media/animation/SparkAnimation.java b/src/java/com/threerings/media/animation/SparkAnimation.java index 15837630d..ac8969cce 100644 --- a/src/java/com/threerings/media/animation/SparkAnimation.java +++ b/src/java/com/threerings/media/animation/SparkAnimation.java @@ -126,24 +126,22 @@ public class SparkAnimation extends Animation return (RandomUtil.getInt(2) == 0) ? -1 : 1; } + // documentation inherited + protected void willStart (long stamp) + { + super.willStart(stamp); + _start = stamp; + } + // documentation inherited public void fastForward (long timeDelta) { - if (_start > 0) { - _start += timeDelta; - _end += timeDelta; - } + _start += timeDelta; } // documentation inherited 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 long msecs = Math.max(timestamp - _start, 0); long msecsSq = msecs * msecs; @@ -155,6 +153,9 @@ public class SparkAnimation extends Animation _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 for (int ii = 0; ii < _icount; ii++) { // determine the travel distance @@ -166,10 +167,17 @@ public class SparkAnimation extends Animation // update the position _xpos[ii] = _ox[ii] + xtrav; _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 - _finished = (timestamp >= _end); + _finished = allOutside || (msecs >= _delay); // dirty ourselves // TODO: only do this if at least one spark actually moved @@ -235,9 +243,6 @@ public class SparkAnimation extends Animation /** The starting animation time. */ protected long _start; - /** The ending animation time. */ - protected long _end; - /** Whether or not we should fade the sparks out. */ protected boolean _fade;