Add the ability to fade the sprite out without a path and fix fading out with a path so that it's actually fading out instead of fading in
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@272 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
package com.threerings.media.sprite;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import com.threerings.media.util.Path;
|
||||
|
||||
@@ -41,6 +41,19 @@ public class FadableImageSprite extends OrientableImageSprite
|
||||
_fadeDelay = delay;
|
||||
_fadeInDuration = duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fades this sprite out over the specified duration after
|
||||
* waiting for the specified delay.
|
||||
*/
|
||||
public void fadeOut (long delay, long duration)
|
||||
{
|
||||
setAlpha(1.0f);
|
||||
|
||||
_fadeStamp = 0;
|
||||
_fadeDelay = delay;
|
||||
_fadeOutDuration = duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts this sprite on the specified path and fades it in over
|
||||
@@ -137,12 +150,33 @@ public class FadableImageSprite extends OrientableImageSprite
|
||||
}
|
||||
}
|
||||
|
||||
} else if (_fadeOutDuration != -1 && _pathStamp+_pathDuration-tickStamp
|
||||
<= _fadeOutDuration) {
|
||||
// fading out while moving
|
||||
float alpha = (float)(_pathStamp+_pathDuration-tickStamp)/
|
||||
_fadeOutDuration;
|
||||
setAlpha(alpha);
|
||||
} else if (_fadeOutDuration != -1) {
|
||||
if (_path != null) {
|
||||
if (tickStamp - _pathStamp <= _fadeOutDuration) {
|
||||
// fading out while moving
|
||||
float alpha = 1f - (_pathStamp + _pathDuration - tickStamp)
|
||||
/ _fadeOutDuration;
|
||||
setAlpha(alpha);
|
||||
}
|
||||
} else {
|
||||
// fading out while stationary
|
||||
if (_fadeStamp == 0) {
|
||||
// store the time at which fade started
|
||||
_fadeStamp = tickStamp;
|
||||
}
|
||||
if (tickStamp > _fadeStamp + _fadeDelay) {
|
||||
// initial delay has passed
|
||||
float alpha = 1f - (float)(tickStamp - _fadeStamp - _fadeDelay) / _fadeOutDuration;
|
||||
if (alpha <= 0.0f) {
|
||||
// fade-out complete
|
||||
setAlpha(0.0f);
|
||||
_fadeOutDuration = -1;
|
||||
|
||||
} else {
|
||||
setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user