Make catcher's trail reflect the current animation frame rather than play the full animation

This commit is contained in:
Dean Herbert 2020-03-11 14:28:13 +09:00
parent 1bad2ff879
commit 73b225ad62
2 changed files with 50 additions and 24 deletions

View File

@ -9,6 +9,8 @@
using osu.Framework.Graphics.Animations; using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -180,31 +182,29 @@ private void load()
private CatcherSprite catcherKiai; private CatcherSprite catcherKiai;
private CatcherSprite catcherFail; private CatcherSprite catcherFail;
private CatcherSprite currentCatcher;
private void updateCatcher() private void updateCatcher()
{ {
catcherIdle.Hide(); currentCatcher?.Hide();
catcherKiai.Hide();
catcherFail.Hide();
CatcherSprite current;
switch (currentState) switch (currentState)
{ {
default: default:
current = catcherIdle; currentCatcher = catcherIdle;
break; break;
case CatcherAnimationState.Fail: case CatcherAnimationState.Fail:
current = catcherFail; currentCatcher = catcherFail;
break; break;
case CatcherAnimationState.Kiai: case CatcherAnimationState.Kiai:
current = catcherKiai; currentCatcher = catcherKiai;
break; break;
} }
current.Show(); currentCatcher.Show();
(current.Drawable as IAnimation)?.GotoFrame(0); (currentCatcher.Drawable as IAnimation)?.GotoFrame(0);
} }
private int currentDirection; private int currentDirection;
@ -227,14 +227,14 @@ protected bool Dashing
private bool trail; private bool trail;
/// <summary> /// <summary>
/// Activate or deactive the trail. Will be automatically deactivated when conditions to keep the trail displayed are no longer met. /// Activate or deactivate the trail. Will be automatically deactivated when conditions to keep the trail displayed are no longer met.
/// </summary> /// </summary>
protected bool Trail protected bool Trail
{ {
get => trail; get => trail;
set set
{ {
if (value == trail) return; if (value == trail || AdditiveTarget == null) return;
trail = value; trail = value;
@ -245,21 +245,25 @@ protected bool Trail
private void beginTrail() private void beginTrail()
{ {
Trail &= dashing || HyperDashing; if (!dashing && !HyperDashing)
Trail &= AdditiveTarget != null; {
Trail = false;
return;
}
if (!Trail) return; Texture tex = (currentCatcher.Drawable as TextureAnimation)?.CurrentFrame ?? ((Sprite)currentCatcher.Drawable).Texture;
var additive = createCatcherSprite(); var additive = new CatcherTrailSprite(tex)
{
Anchor = Anchor,
Scale = Scale,
Colour = HyperDashing ? Color4.Red : Color4.White,
Blending = BlendingParameters.Additive,
RelativePositionAxes = RelativePositionAxes,
Position = Position
};
additive.Anchor = Anchor; AdditiveTarget?.Add(additive);
additive.Scale = Scale;
additive.Colour = HyperDashing ? Color4.Red : Color4.White;
additive.Blending = BlendingParameters.Additive;
additive.RelativePositionAxes = RelativePositionAxes;
additive.Position = Position;
AdditiveTarget.Add(additive);
additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint); additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint);
additive.Expire(true); additive.Expire(true);

View File

@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;
namespace osu.Game.Rulesets.Catch.UI
{
public class CatcherTrailSprite : Sprite
{
public CatcherTrailSprite(Texture texture)
{
Texture = texture;
Size = new Vector2(CatcherArea.CATCHER_SIZE);
// Sets the origin roughly to the centre of the catcher's plate to allow for correct scaling.
OriginPosition = new Vector2(0.5f, 0.06f) * CatcherArea.CATCHER_SIZE;
}
}
}