mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 17:27:48 +08:00
Move shake logic into extension method
This commit is contained in:
parent
7bd749d0eb
commit
e17b800470
@ -38,6 +38,33 @@ namespace osu.Game.Extensions
|
|||||||
return repeatDelegate;
|
return repeatDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shake the contents of this container.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">The target to shake.</param>
|
||||||
|
/// <param name="shakeDuration">The length of a single shake.</param>
|
||||||
|
/// <param name="shakeMagnitude">Pixels of displacement per shake.</param>
|
||||||
|
/// <param name="maximumLength">The maximum length the shake should last.</param>
|
||||||
|
public static void Shake(this Drawable target, double shakeDuration = 80, float shakeMagnitude = 8, double? maximumLength = null)
|
||||||
|
{
|
||||||
|
// if we don't have enough time, don't bother shaking.
|
||||||
|
if (maximumLength < shakeDuration * 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var sequence = target.MoveToX(shakeMagnitude, shakeDuration / 2, Easing.OutSine).Then()
|
||||||
|
.MoveToX(-shakeMagnitude, shakeDuration, Easing.InOutSine).Then();
|
||||||
|
|
||||||
|
// if we don't have enough time for the second shake, skip it.
|
||||||
|
if (!maximumLength.HasValue || maximumLength >= shakeDuration * 4)
|
||||||
|
{
|
||||||
|
sequence = sequence
|
||||||
|
.MoveToX(shakeMagnitude, shakeDuration, Easing.InOutSine).Then()
|
||||||
|
.MoveToX(-shakeMagnitude, shakeDuration, Easing.InOutSine).Then();
|
||||||
|
}
|
||||||
|
|
||||||
|
sequence.MoveToX(0, shakeDuration / 2, Easing.InSine);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Accepts a delta vector in screen-space coordinates and converts it to one which can be applied to this drawable's position.
|
/// Accepts a delta vector in screen-space coordinates and converts it to one which can be applied to this drawable's position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Extensions;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers
|
namespace osu.Game.Graphics.Containers
|
||||||
{
|
{
|
||||||
@ -16,40 +16,10 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float ShakeDuration = 80;
|
public float ShakeDuration = 80;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Total number of shakes. May be shortened if possible.
|
|
||||||
/// </summary>
|
|
||||||
public float TotalShakes = 4;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Pixels of displacement per shake.
|
|
||||||
/// </summary>
|
|
||||||
public float ShakeMagnitude = 8;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shake the contents of this container.
|
/// Shake the contents of this container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="maximumLength">The maximum length the shake should last.</param>
|
/// <param name="maximumLength">The maximum length the shake should last.</param>
|
||||||
public void Shake(double? maximumLength = null)
|
public void Shake(double? maximumLength = null) => this.Shake(ShakeDuration, maximumLength: maximumLength);
|
||||||
{
|
|
||||||
const float shake_amount = 8;
|
|
||||||
|
|
||||||
// if we don't have enough time, don't bother shaking.
|
|
||||||
if (maximumLength < ShakeDuration * 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var sequence = this.MoveToX(shake_amount, ShakeDuration / 2, Easing.OutSine).Then()
|
|
||||||
.MoveToX(-shake_amount, ShakeDuration, Easing.InOutSine).Then();
|
|
||||||
|
|
||||||
// if we don't have enough time for the second shake, skip it.
|
|
||||||
if (!maximumLength.HasValue || maximumLength >= ShakeDuration * 4)
|
|
||||||
{
|
|
||||||
sequence = sequence
|
|
||||||
.MoveToX(shake_amount, ShakeDuration, Easing.InOutSine).Then()
|
|
||||||
.MoveToX(-shake_amount, ShakeDuration, Easing.InOutSine).Then();
|
|
||||||
}
|
|
||||||
|
|
||||||
sequence.MoveToX(0, ShakeDuration / 2, Easing.InSine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user