Restructure explosion animation to avoid resetting transforms on free

This commit is contained in:
Bartłomiej Dach 2021-03-15 20:48:19 +01:00
parent f4e508b570
commit 72c18fbdfe
1 changed files with 17 additions and 15 deletions

View File

@ -25,6 +25,8 @@ internal class HitExplosion : PoolableDrawable
private readonly HitResult result; private readonly HitResult result;
private double? secondHitTime;
[CanBeNull] [CanBeNull]
public DrawableHitObject JudgedObject; public DrawableHitObject JudgedObject;
@ -61,6 +63,7 @@ private void load()
public void Apply([CanBeNull] DrawableHitObject drawableHitObject) public void Apply([CanBeNull] DrawableHitObject drawableHitObject)
{ {
JudgedObject = drawableHitObject; JudgedObject = drawableHitObject;
secondHitTime = null;
} }
protected override void PrepareForUse() protected override void PrepareForUse()
@ -69,16 +72,6 @@ protected override void PrepareForUse()
runAnimation(); runAnimation();
} }
protected override void FreeAfterUse()
{
base.FreeAfterUse();
// clean up transforms on free instead of on prepare as is usually the case
// to avoid potentially overriding the effects of VisualiseSecondHit() in the case it is called before PrepareForUse().
ApplyTransformsAt(double.MinValue, true);
ClearTransforms(true);
}
private void runAnimation() private void runAnimation()
{ {
if (JudgedObject?.Result == null) if (JudgedObject?.Result == null)
@ -88,9 +81,21 @@ private void runAnimation()
LifetimeStart = resultTime; LifetimeStart = resultTime;
ApplyTransformsAt(double.MinValue, true);
ClearTransforms(true);
using (BeginAbsoluteSequence(resultTime)) using (BeginAbsoluteSequence(resultTime))
(skinnable.Drawable as IAnimatableHitExplosion)?.Animate(JudgedObject); (skinnable.Drawable as IAnimatableHitExplosion)?.Animate(JudgedObject);
if (secondHitTime != null)
{
using (BeginAbsoluteSequence(secondHitTime.Value))
{
this.ResizeTo(new Vector2(TaikoStrongableHitObject.DEFAULT_STRONG_SIZE), 50);
(skinnable.Drawable as IAnimatableHitExplosion)?.AnimateSecondHit();
}
}
LifetimeEnd = skinnable.Drawable.LatestTransformEndTime; LifetimeEnd = skinnable.Drawable.LatestTransformEndTime;
} }
@ -113,11 +118,8 @@ private static TaikoSkinComponents getComponentName(HitResult result)
public void VisualiseSecondHit(JudgementResult judgementResult) public void VisualiseSecondHit(JudgementResult judgementResult)
{ {
using (BeginAbsoluteSequence(judgementResult.TimeAbsolute)) secondHitTime = judgementResult.TimeAbsolute;
{ runAnimation();
this.ResizeTo(new Vector2(TaikoStrongableHitObject.DEFAULT_STRONG_SIZE), 50);
(skinnable.Drawable as IAnimatableHitExplosion)?.AnimateSecondHit();
}
} }
} }
} }