using DotSDL.Interop.Core; using DotSDL.Math.Vector; using SdlPixels = DotSDL.Interop.Core.Pixels; namespace DotSDL.Graphics { /// /// Represents a graphical, two-dimensional object in a program. /// public class Sprite : Canvas { /// /// The position on the screen where the should be drawn. /// public Point Position { get; set; } /// /// The angle that the sprite is drawn, in degrees. Incrementing this will rotate the /// sprite clockwise. /// public float Rotation { get; set; } /// /// The point around which the sprite will be rotated. By default, this will be set to /// the center of the sprite. /// public Point RotationCenter { get; set; } /// /// Indicates which axes this sprice should be flipped across, if any. /// public FlipDirection Flip { get; set; } /// /// The scale of the . 1.0f is 100%. /// public Vector2 Scale { get; set; } /// public override ScalingQuality ScalingQuality { get => ScalingQualityValue; set { ScalingQualityValue = value; if(HasTexture) { CreateTexture(); UpdateTexture(); } } } /// /// true if the sprite should be drawn to the screen, otherwise false. /// public bool Shown { get; set; } /// /// The order in which the sprite is drawn. Lower numbered instances are drawn first /// and will appear on the bottom. /// public int ZOrder { get; set; } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . public Sprite(int width, int height) : this(width, height, Point.Zero, Vector2.One, 0) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A representing the initial position of the new . public Sprite(int width, int height, Point position) : this(width, height, position, Vector2.One, 0) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A value indicating the order in which this is drawn. Higher numbered /// sprites are drawn on top of other sprites and, thus, will appear above them. public Sprite(int width, int height, int zOrder) : this(width, height, Point.Zero, Vector2.One, zOrder) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A representing the initial position of the new . /// A representing the initial scaling of the new . public Sprite(int width, int height, Point position, Vector2 scale) : this(width, height, position, scale, 0) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A representing the initial position of the new . /// A value indicating the order in which this is drawn. Higher numbered /// sprites are drawn on top of other sprites and, thus, will appear above them. public Sprite(int width, int height, Point position, int zOrder) : this(width, height, position, Vector2.One, 0) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A representing the initial position of the new . /// A representing the initial scaling of the new . /// A value indicating the order in which this is drawn. Higher numbered /// sprites are drawn on top of other sprites and, thus, will appear above them. public Sprite(int width, int height, Point position, Vector2 scale, int zOrder) : this(width, height, position, new Rectangle(0, 0, width, height), scale, zOrder) { } /// /// Initializes a new . /// /// The width of the new . /// The height of the new . /// A representing the initial position of the new . /// A representing the initial scaling of the new . /// A rectangle specifying which part of this should be drawn. /// A value indicating the order in which this is drawn. Higher numbered /// sprites are drawn on top of other sprites and, thus, will appear above them. public Sprite(int width, int height, Point position, Rectangle clipping, Vector2 scale, int zOrder) : base(width, height, clipping) { Position = position; Scale = scale; ZOrder = zOrder; Shown = false; RotationCenter = new Point(clipping.Size.X / 2, clipping.Size.Y / 2); } /// /// Creates a texture or recreates it if it already exists. /// internal override void CreateTexture() { CreateTexture(Render.TextureAccess.Static); } /// /// Updates the texture associated with this . This function must be called when the /// array is changed after adding this sprite to the sprite list associated /// with the application's . /// /// true if the texture was successfully updated, otherwise false. This will return false if this hasn't been added to the sprite list. public new bool UpdateTexture() { return base.UpdateTexture(); } } }