From ffdff82b425c7f0ed32e9a89a1a632915c2f48ba Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Thu, 31 Jan 2002 17:35:41 +0000 Subject: [PATCH] Added setStartTime() to allow synchronizing multiple fade animations to the same starting time. Constrain the alpha to a valid range before getting the composite object. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@908 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../media/animation/FadeAnimation.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/media/animation/FadeAnimation.java b/src/java/com/threerings/media/animation/FadeAnimation.java index 9dbc182e3..eb1445da3 100644 --- a/src/java/com/threerings/media/animation/FadeAnimation.java +++ b/src/java/com/threerings/media/animation/FadeAnimation.java @@ -1,5 +1,5 @@ // -// $Id: FadeAnimation.java,v 1.2 2002/01/11 16:53:34 shaper Exp $ +// $Id: FadeAnimation.java,v 1.3 2002/01/31 17:35:41 shaper Exp $ package com.threerings.media.animation; @@ -44,9 +44,14 @@ public class FadeAnimation extends Animation // create the initial composite _comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha); + } - // save the animation starting time - _start = System.currentTimeMillis(); + /** + * Sets the animation starting time. + */ + public void setStartTime (long timestamp) + { + _start = timestamp; } // documentation inherited @@ -54,7 +59,13 @@ public class FadeAnimation extends Animation { // figure out the current alpha long msecs = timestamp - _start; - _alpha = Math.min(_startAlpha + (msecs * _step), 1.0f); + _alpha = _startAlpha + (msecs * _step); + if (_alpha < 0.0f) { + _alpha = 0.0f; + } else if (_alpha > 1.0f) { + _alpha = 1.0f; + } + _comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha); // check whether we're done