A game framework written with osu! in mind.
at master 51 lines 2.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4namespace osu.Framework.Graphics.Animations 5{ 6 /// <summary> 7 /// This class holds various extension methods for the <see cref="IFramedAnimation"/> interface. 8 /// </summary> 9 public static class FramedAnimationExtensions 10 { 11 /// <summary> 12 /// Displays the frame with the given zero-based frame index and stops the animation at that frame. 13 /// </summary> 14 /// <param name="animation">The animation that should seek the frame and stop playing.</param> 15 /// <param name="frameIndex">The zero-based index of the frame to display.</param> 16 public static void GotoAndStop(this IFramedAnimation animation, int frameIndex) 17 { 18 animation.GotoFrame(frameIndex); 19 animation.IsPlaying = false; 20 } 21 22 /// <summary> 23 /// Displays the frame with the given zero-based frame index and plays the animation from that frame. 24 /// </summary> 25 /// <param name="animation">The animation that should seek the frame and start playing.</param> 26 /// <param name="frameIndex">The zero-based index of the frame to display.</param> 27 public static void GotoAndPlay(this IFramedAnimation animation, int frameIndex) 28 { 29 animation.GotoFrame(frameIndex); 30 animation.IsPlaying = true; 31 } 32 33 /// <summary> 34 /// Resumes playing the animation. 35 /// </summary> 36 /// <param name="animation">The animation to play.</param> 37 public static void Play(this IFramedAnimation animation) => animation.IsPlaying = true; 38 39 /// <summary> 40 /// Stops playing the animation. 41 /// </summary> 42 /// <param name="animation">The animation to stop playing.</param> 43 public static void Stop(this IFramedAnimation animation) => animation.IsPlaying = false; 44 45 /// <summary> 46 /// Restarts the animation. 47 /// </summary> 48 /// <param name="animation">The animation to restart.</param> 49 public static void Restart(this IFramedAnimation animation) => animation.GotoAndPlay(0); 50 } 51}