Simplify and combine fading out for both moving and stationary sprites.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@276 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -87,8 +87,10 @@ public class FadableImageSprite extends OrientableImageSprite
|
|||||||
|
|
||||||
setAlpha(1.0f);
|
setAlpha(1.0f);
|
||||||
|
|
||||||
|
_fadeStamp = 0;
|
||||||
_pathDuration = pathDuration;
|
_pathDuration = pathDuration;
|
||||||
_fadeOutDuration = (long)(pathDuration*fadePortion);
|
_fadeOutDuration = (long)(pathDuration*fadePortion);
|
||||||
|
_fadeDelay = _pathDuration - _fadeOutDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,8 +139,7 @@ public class FadableImageSprite extends OrientableImageSprite
|
|||||||
}
|
}
|
||||||
if (tickStamp > _fadeStamp + _fadeDelay) {
|
if (tickStamp > _fadeStamp + _fadeDelay) {
|
||||||
// initial delay has passed
|
// initial delay has passed
|
||||||
float alpha = (float)(tickStamp-_fadeStamp-_fadeDelay)/
|
float alpha = (float)(tickStamp-_fadeStamp-_fadeDelay) / _fadeInDuration;
|
||||||
_fadeInDuration;
|
|
||||||
if (alpha >= 1.0f) {
|
if (alpha >= 1.0f) {
|
||||||
// fade-in complete
|
// fade-in complete
|
||||||
setAlpha(1.0f);
|
setAlpha(1.0f);
|
||||||
@@ -151,30 +152,21 @@ public class FadableImageSprite extends OrientableImageSprite
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (_fadeOutDuration != -1) {
|
} else if (_fadeOutDuration != -1) {
|
||||||
if (_path != null) {
|
if (_fadeStamp == 0) {
|
||||||
if (tickStamp - _pathStamp <= _fadeOutDuration) {
|
// store the time at which fade started
|
||||||
// fading out while moving
|
_fadeStamp = tickStamp;
|
||||||
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 {
|
if (tickStamp > _fadeStamp + _fadeDelay) {
|
||||||
setAlpha(alpha);
|
// 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