A game framework written with osu! in mind.
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
4using System.Linq;
5using osu.Framework.Graphics.Containers;
6using osuTK;
7
8namespace osu.Framework.Graphics.Animations
9{
10 /// <summary>
11 /// An animation that switches the displayed drawable when a new frame is displayed.
12 /// </summary>
13 public class DrawableAnimation : Animation<Drawable>
14 {
15 private Container container;
16
17 protected override void DisplayFrame(Drawable content)
18 {
19 // don't dispose previous frames as they may be displayed again.
20 container.Clear(false);
21
22 container.Child = content;
23 }
24
25 public override Drawable CreateContent() => container = new Container { RelativeSizeAxes = Axes.Both };
26
27 protected override Vector2 GetCurrentDisplaySize() => container.Children.FirstOrDefault()?.DrawSize ?? Vector2.Zero;
28
29 protected override float GetFillAspectRatio() => container.Children.FirstOrDefault()?.FillAspectRatio ?? 1;
30 }
31}