Skip to content

AnimatedScreenObject Class

A ScreenObject that displays an animated set of ICellSurface surfaces.

C#
[DataContract]
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class AnimatedScreenObject : ScreenObject, IScreenSurface, IScreenObject, IPositionable, IComponentHost

Inheritance objectScreenObject

Implements IScreenSurface, IScreenObject, SadRogue.Primitives.IPositionable, IComponentHost

Creates a new animation with the specified name, width, and height.

C#
public AnimatedScreenObject(string name, int width, int height)

name string
The name of the animation.

width int
The width of each frame this animation will have.

height int
The height of each frame this animation will have.

AnimatedScreenObject(string, IEnumerable<ICellSurface>)

Section titled “AnimatedScreenObject(string, IEnumerable<ICellSurface>)”

Creates a new animation with the specified name and frames.

C#
public AnimatedScreenObject(string name, IEnumerable<ICellSurface> frames)

name string
The name of the animation.

frames IEnumerable<ICellSurface>
The frames that make up the animation.

AnimatedScreenObject(string, int, int, IFont, Point)

Section titled “AnimatedScreenObject(string, int, int, IFont, Point)”

Creates a new animation with the specified name, width, and height.

C#
public AnimatedScreenObject(string name, int width, int height, IFont font, Point fontSize)

name string
The name of the animation.

width int
The width of each frame this animation will have.

height int
The height of each frame this animation will have.

font IFont
The font used with this animation.

fontSize SadRogue.Primitives.Point
The size of the font.

AnimatedScreenObject(string, IFont, Point, IEnumerable<ICellSurface>)

Section titled “AnimatedScreenObject(string, IFont, Point, IEnumerable<ICellSurface>)”
C#
[JsonConstructor]
public AnimatedScreenObject(string name, IFont font, Point fontSize, IEnumerable<ICellSurface> frames)

name string

font IFont

fontSize SadRogue.Primitives.Point

frames IEnumerable<ICellSurface>

Time counter for the animation

C#
protected TimeSpan AddedTime

The current frame index being animated.

C#
protected int CurrentFrameIndexValue

How much time per animated frame should be used.

C#
protected TimeSpan TimePerFrame

Indicates that the mouse is currently over this console.

C#
protected bool IsMouseOver

The width to assign a frame when CreateFrame() is called.

C#
[DataMember]
protected int NewFrameWidth

The height to assign a frame when CreateFrame() is called.

C#
[DataMember]
protected int NewFrameHeight

Center of the animation used in positioning.

C#
[DataMember]
public Point Center { get; set; }

Indicates whether or not this animation will repeat once it has finished animating.

C#
[DataMember]
public bool Repeat { get; set; }

When true, Indicates the animation is currently animating. The Update(TimeSpan) method will advance the frames.

C#
[DataMember]
public bool IsPlaying { get; protected set; }

The length of the animation.

C#
[DataMember]
public TimeSpan AnimationDuration { get; set; }

Gets or sets the current frame index to animate.

C#
public int CurrentFrameIndex { get; set; }

Indicates the animation is empty.

C#
public bool IsEmpty { get; }

The frames of the animated surface.

C#
[DataMember]
public List<ICellSurface> Frames { get; }

Gets the name of this animation.

C#
[DataMember]
public string Name { get; set; }

Gets the current animation state.

C#
public AnimatedScreenObject.AnimationState State { get; set; }

When true, this object will move to the front of its parent object when the mouse is clicked.

C#
[DataMember]
public bool MoveToFrontOnMouseClick { get; set; }

When true, this object will set IsFocused to true when the mouse is clicked.

C#
[DataMember]
public bool FocusOnMouseClick { get; set; }

When true, forces the Renderer to refresh the backing texture with the latest state of the object.

C#
public bool ForceRendererRefresh { get; set; }

The name of the default renderer for this object.

C#
public virtual string DefaultRendererName { get; }

The renderer used to draw this surface.

C#
[DataMember]
[JsonConverter(typeof(RendererJsonConverter))]
public IRenderer? Renderer { get; set; }

When true, indicates that the animation needs to be redrawn; otherwise false.

C#
public bool IsDirty { get; set; }

Font used with rendering.

C#
public IFont Font { get; set; }

The size of the Font cells applied to the object when rendering.

C#
public Point FontSize { get; set; }

A tint used in rendering.

C#
public Color Tint { get; set; }

The pixel area on the screen this surface occupies.

C#
public Rectangle AbsoluteArea { get; }

Treats the SadRogue.Primitives.IPositionable.Position of the object as if it is pixels and not cells.

C#
public bool UsePixelPositioning { get; set; }

The width of the surface in pixels.

C#
public int WidthPixels { get; }

The height of the surface in pixels.

C#
public int HeightPixels { get; }

The total width of the console.

C#
public int Width { get; }

The total height of the console.

C#
public int Height { get; }

Gets or sets the visible width of the surface in cells.

C#
public int ViewWidth { get; set; }

Gets or sets the visible height of the surface in cells.

C#
public int ViewHeight { get; set; }

The position of the view within the console.

C#
public Point ViewPosition { get; set; }

Gets the current animation frame surface. A shortcut for

Frames[CurrentFrameIndex]

C#
public ICellSurface CurrentFrame { get; }

Creates a new frame with the same dimensions as this entity and adds it to the Frames collection of the entity.

C#
public ICellSurface CreateFrame()

ICellSurface
The created frame.

Stops animating.

C#
public void Stop()

Starts animating the frames.

C#
public void Start()

Restarts the animation from the first frame.

C#
public void Restart()

Changes the CurrentFrame to the next frame.

C#
public void MoveNext(bool circular = false)

circular bool
If true and the current frame is the last, sets the current frame to the first frame.

Changes the CurrentFrame to the previous frame.

C#
public void MovePrevious(bool circular = false)

circular bool
If true and the current frame is the first, sets the current frame to the last frame.

Changes the CurrentFrame to the last frame.

C#
public void MoveEnd()

Changes the CurrentFrame to the first frame.

C#
public void MoveStart()

CreateStatic(int, int, int, double, Color?, Color?)

Section titled “CreateStatic(int, int, int, double, Color?, Color?)”

Creates an animated surface that looks like static noise.

C#
public static AnimatedScreenObject CreateStatic(int width, int height, int frames, double blankChance, Color? background = null, Color? foreground = null)

width int
The width of the surface.

height int
The height of the surface.

frames int
How many frames the animation should have.

blankChance double
Chance a character will be blank. Characters are between index 48-158. Chance is evaluated versus NextDouble().

background System.NullableSadRogue.Primitives.Color
The background color of the animation. Defaults to transparent.

foreground System.NullableSadRogue.Primitives.Color
The foreground color of the animation. Defaults to white.

AnimatedScreenObject
An animation.

FromImage(string, string, Point, TimeSpan, Point?, Point?, IFont?, Action<ColoredGlyphBase>?, TextureConvertMode, TextureConvertForegroundStyle, TextureConvertBackgroundStyle, Color?)

Section titled “FromImage(string, string, Point, TimeSpan, Point?, Point?, IFont?, Action<ColoredGlyphBase>?, TextureConvertMode, TextureConvertForegroundStyle, TextureConvertBackgroundStyle, Color?)”

Converts an image file containing frames to an instance of AnimatedScreenObject.

C#
public static AnimatedScreenObject FromImage(string name, string filePath, Point frameLayout, TimeSpan frameDuration, Point? pixelPadding = null, Point? frameStartAndFinish = null, IFont? font = null, Action<ColoredGlyphBase>? action = null, TextureConvertMode convertMode = TextureConvertMode.Foreground, TextureConvertForegroundStyle convertForegroundStyle = TextureConvertForegroundStyle.Block, TextureConvertBackgroundStyle convertBackgroundStyle = TextureConvertBackgroundStyle.Pixel, Color? frameDefaultBackground = null)

name string
Name for the animation.

filePath string
File path to the image file.

frameLayout SadRogue.Primitives.Point
Layout of frames in the image file: X number of columns, Y number of rows.

frameDuration TimeSpan
Duration for a frame in the animation.

pixelPadding System.NullableSadRogue.Primitives.Point
Pixel padding separating frames: X between the columns, Y between the rows.

frameStartAndFinish System.NullableSadRogue.Primitives.Point
Limits the number of frames copied to the animation. X first frame index, Y last frame index.

font IFont
IFont to be used when creating the AnimatedScreenObject.

action Action<ColoredGlyphBase>
Callback that will be applied to each ColoredGlyphBase when creating a frame.

convertMode TextureConvertMode
The mode used when converting the texture to a surface.

convertForegroundStyle TextureConvertForegroundStyle
The style to use when convertMode is Foreground.

convertBackgroundStyle TextureConvertBackgroundStyle
The style to use when convertMode is Background.

frameDefaultBackground System.NullableSadRogue.Primitives.Color
The default background to use in the animation frames. Defaults to transparent.

AnimatedScreenObject
An instance of AnimatedScreenObject with converted frames.

This method assumes the image file contains only frames and optional padding between the frames, no border space. Frame count is calculated by multiplying rows and columns from the frame layout. It can by limited by specifying frame start and finish indexes. Frame size and the subsequent AnimatedScreenSurface size is calculated from the size of the image file, number of frames, padding and the font size ratio.

Saves the AnimatedScreenObject to a file.

C#
public void Save(string file)

file string
The destination file.

Loads a AnimatedScreenObject from a file.

C#
public static AnimatedScreenObject Load(string file)

file string
The source file.

AnimatedScreenObject
The animated surface.

Raises the MouseEnter event.

C#
protected virtual void OnMouseEnter(MouseScreenObjectState state)

state MouseScreenObjectState
Current mouse state in relation to this console.

Raises the MouseExit event.

C#
protected virtual void OnMouseExit(MouseScreenObjectState state)

state MouseScreenObjectState
Current mouse state in relation to this console.

Raises the MouseMove event.

C#
protected virtual void OnMouseMove(MouseScreenObjectState state)

state MouseScreenObjectState
Current mouse state in relation to this console.

OnMouseLeftClicked(MouseScreenObjectState)

Section titled “OnMouseLeftClicked(MouseScreenObjectState)”

Raises the MouseButtonClicked event. Possibly moves the console to the top of it’s parent’s children collection.

C#
protected virtual void OnMouseLeftClicked(MouseScreenObjectState state)

state MouseScreenObjectState
Current mouse state in relation to this console.

OnRightMouseClicked(MouseScreenObjectState)

Section titled “OnRightMouseClicked(MouseScreenObjectState)”

Raises the MouseButtonClicked event.

C#
protected virtual void OnRightMouseClicked(MouseScreenObjectState state)

state MouseScreenObjectState
Current mouse state in relation to this console.

Called when the mouse is being used by something else.

C#
public override void LostMouse(MouseScreenObjectState state)

state MouseScreenObjectState
The current state of the mouse based on this object.

Processes the mouse.

C#
public override bool ProcessMouse(MouseScreenObjectState state)

state MouseScreenObjectState
The mouse state related to this object.

bool
True when this object should halt further mouse processing..

Sets a value for AbsolutePosition based on the SadRogue.Primitives.IPositionable.Position of this instance and the Parent instance.

C#
public override void UpdateAbsolutePosition()

Draws the animation’s current frame and all SadComponents and Children.

C#
public override void Render(TimeSpan delta)

delta TimeSpan
The time that has elapsed since the last call.

Updates the AnimatedScreenObject effects and all SadComponents and Children.

C#
public override void Update(TimeSpan delta)

delta TimeSpan
The time that has elapsed since this method was last called.

Returns the value “ScreenSurface”.

C#
public override string ToString()

string
The string “ScreenSurface”.

C#
protected virtual void Dispose(bool disposing)

disposing bool

Disposes Renderer.

C#
protected ~AnimatedScreenObject()
C#
public void Dispose()

Raised when the AnimatedScreenObject.AnimationState changes.

C#
public event EventHandler<AnimatedScreenObject.AnimationStateChangedEventArgs>? AnimationStateChanged

EventHandler<AnimatedScreenObject.AnimationStateChangedEventArgs>

Raised when a mouse button is clicked on this object.

C#
public event EventHandler<MouseScreenObjectState>? MouseButtonClicked

EventHandler<MouseScreenObjectState>

Raised when the mouse moves around the this object.

C#
public event EventHandler<MouseScreenObjectState>? MouseMove

EventHandler<MouseScreenObjectState>

Raised when the mouse exits this object.

C#
public event EventHandler<MouseScreenObjectState>? MouseExit

EventHandler<MouseScreenObjectState>

Raised when the mouse enters this object.

C#
public event EventHandler<MouseScreenObjectState>? MouseEnter

EventHandler<MouseScreenObjectState>