fix fading
This commit is contained in:
@@ -343,33 +343,47 @@ void SceneAsset::updateEmbeddedAnimations() {
|
|||||||
duration_cast<duration<double>>(now - status.startedAt);
|
duration_cast<duration<double>>(now - status.startedAt);
|
||||||
float animationTimeOffset = 0;
|
float animationTimeOffset = 0;
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
|
bool fading = false;
|
||||||
|
|
||||||
|
// if the animation hasn't started yet, start the animation at time zero
|
||||||
if (!status.started) {
|
if (!status.started) {
|
||||||
|
|
||||||
status.started = true;
|
status.started = true;
|
||||||
status.startedAt = now;
|
status.startedAt = now;
|
||||||
|
|
||||||
|
// if the animation has finished
|
||||||
} else if (elapsed.count() >= animationLength) {
|
} else if (elapsed.count() >= animationLength) {
|
||||||
if (status.loop) {
|
// if we aren't looping, just mark the animation as finished
|
||||||
status.startedAt = now;
|
if(!status.loop) {
|
||||||
} else {
|
|
||||||
animationTimeOffset = elapsed.count();
|
|
||||||
finished = true;
|
finished = true;
|
||||||
|
// otherwise, cross-fade between the end of the animation and the start frame over 1 second
|
||||||
|
} else {
|
||||||
|
// if 1 second has elapsed,
|
||||||
|
if(elapsed.count() >= animationLength + 0.3) {
|
||||||
|
// reset the start time to zero
|
||||||
|
status.startedAt = now;
|
||||||
|
// otherwise, apply the first frame of the animation, then cross-fade with the last frame over 1 second
|
||||||
|
} else {
|
||||||
|
fading = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
animationTimeOffset = elapsed.count();
|
animationTimeOffset = elapsed.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(status.reverse) {
|
if (finished) {
|
||||||
animationTimeOffset = _animator->getAnimationDuration(animationIndex) - animationTimeOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!finished) {
|
|
||||||
_animator->applyAnimation(animationIndex, animationTimeOffset);
|
|
||||||
} else {
|
|
||||||
Log("Animation %d finished", animationIndex);
|
Log("Animation %d finished", animationIndex);
|
||||||
|
|
||||||
status.play = false;
|
status.play = false;
|
||||||
status.started = false;
|
status.started = false;
|
||||||
}
|
} else {
|
||||||
|
if(status.reverse) {
|
||||||
|
animationTimeOffset = _animator->getAnimationDuration(animationIndex) - animationTimeOffset;
|
||||||
|
}
|
||||||
|
_animator->applyAnimation(animationIndex, animationTimeOffset);
|
||||||
|
if(fading) {
|
||||||
|
// Log("Fading at %0f offset %f", elapsed.count() - animationLength, animationTimeOffset);
|
||||||
|
_animator->applyCrossFade(animationIndex, animationLength - 0.05, (elapsed.count() - animationLength) / 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
animationIndex++;
|
animationIndex++;
|
||||||
}
|
}
|
||||||
if(playing)
|
if(playing)
|
||||||
@@ -379,8 +393,6 @@ void SceneAsset::updateEmbeddedAnimations() {
|
|||||||
unique_ptr<vector<string>> SceneAsset::getAnimationNames() {
|
unique_ptr<vector<string>> SceneAsset::getAnimationNames() {
|
||||||
size_t count = _animator->getAnimationCount();
|
size_t count = _animator->getAnimationCount();
|
||||||
|
|
||||||
Log("Found %d animations in asset.", count);
|
|
||||||
|
|
||||||
unique_ptr<vector<string>> names = make_unique<vector<string>>();
|
unique_ptr<vector<string>> names = make_unique<vector<string>>();
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user