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 osuTK;
5using osu.Framework.Graphics.Sprites;
6using osu.Framework.Graphics.Textures;
7
8namespace osu.Framework.Graphics.Animations
9{
10 /// <summary>
11 /// An animation that switches the displayed texture when a new frame is displayed.
12 /// </summary>
13 public class TextureAnimation : Animation<Texture>
14 {
15 private Sprite textureHolder;
16
17 public TextureAnimation(bool startAtCurrentTime = true)
18 : base(startAtCurrentTime)
19 {
20 }
21
22 public override Drawable CreateContent() => textureHolder = new Sprite
23 {
24 RelativeSizeAxes = Axes.Both,
25 Anchor = Anchor.Centre,
26 Origin = Anchor.Centre,
27 };
28
29 protected override void DisplayFrame(Texture content) => textureHolder.Texture = content;
30
31 protected override float GetFillAspectRatio() => textureHolder.FillAspectRatio;
32
33 protected override Vector2 GetCurrentDisplaySize() =>
34 new Vector2(textureHolder.Texture?.DisplayWidth ?? 0, textureHolder.Texture?.DisplayHeight ?? 0);
35 }
36}