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;
|
package com.threerings.media.sprite;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Composite;
|
import java.awt.Composite;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
import com.threerings.media.util.Path;
|
import com.threerings.media.util.Path;
|
||||||
|
|
||||||
@@ -42,6 +42,19 @@ public class FadableImageSprite extends OrientableImageSprite
|
|||||||
_fadeInDuration = duration;
|
_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
|
* Puts this sprite on the specified path and fades it in over
|
||||||
* the specified duration.
|
* the specified duration.
|
||||||
@@ -137,12 +150,33 @@ public class FadableImageSprite extends OrientableImageSprite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (_fadeOutDuration != -1 && _pathStamp+_pathDuration-tickStamp
|
} else if (_fadeOutDuration != -1) {
|
||||||
<= _fadeOutDuration) {
|
if (_path != null) {
|
||||||
// fading out while moving
|
if (tickStamp - _pathStamp <= _fadeOutDuration) {
|
||||||
float alpha = (float)(_pathStamp+_pathDuration-tickStamp)/
|
// fading out while moving
|
||||||
_fadeOutDuration;
|
float alpha = 1f - (_pathStamp + _pathDuration - tickStamp)
|
||||||
setAlpha(alpha);
|
/ _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