1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-14 10:09:09 +01:00
MLEM/MLEM.Ui/Elements/SpriteAnimationImage.cs

47 lines
2 KiB
C#
Raw Normal View History

2019-09-12 18:44:24 +02:00
using Microsoft.Xna.Framework;
using MLEM.Animations;
namespace MLEM.Ui.Elements {
2020-05-22 17:02:24 +02:00
/// <summary>
/// A sprite animation image for use inside of a <see cref="UiSystem"/>.
/// A sprite animation image is an <see cref="Image"/> that displays a <see cref="SpriteAnimation"/> or <see cref="SpriteAnimationGroup"/>.
/// </summary>
2019-09-12 18:44:24 +02:00
public class SpriteAnimationImage : Image {
2020-05-22 17:02:24 +02:00
/// <summary>
/// The sprite animation group that is displayed by this image
/// </summary>
2019-09-12 18:44:24 +02:00
public SpriteAnimationGroup Group;
2020-05-22 17:02:24 +02:00
/// <summary>
/// Creates a new sprite animation image with the given settings
/// </summary>
/// <param name="anchor">The image's anchor</param>
/// <param name="size">The image's size</param>
/// <param name="group">The sprite animation group to display</param>
/// <param name="scaleToImage">Whether this image element should scale to the texture</param>
public SpriteAnimationImage(Anchor anchor, Vector2 size, SpriteAnimationGroup group, bool scaleToImage = false) :
base(anchor, size, group.CurrentRegion, scaleToImage) {
2019-09-12 18:44:24 +02:00
this.Group = group;
}
2020-05-22 17:02:24 +02:00
/// <summary>
/// Creates a new sprite animation image with the given settings
/// </summary>
/// <param name="anchor">The image's anchor</param>
/// <param name="size">The image's size</param>
/// <param name="animation">The sprite group to display</param>
/// <param name="scaleToImage">Whether this image element should scale to the texture</param>
public SpriteAnimationImage(Anchor anchor, Vector2 size, SpriteAnimation animation, bool scaleToImage = false) :
this(anchor, size, new SpriteAnimationGroup().Add(animation, () => true), scaleToImage) {
2019-09-12 18:44:24 +02:00
}
2020-05-22 17:02:24 +02:00
/// <inheritdoc />
2019-09-12 18:44:24 +02:00
public override void Update(GameTime time) {
base.Update(time);
this.Group.Update(time);
this.Texture = this.Group.CurrentRegion;
}
}
}