Class SkiaSprite
Renders animated sprite sheets by subclassing AnimatedFramesRenderer
public class SkiaSprite : AnimatedFramesRenderer, INotifyPropertyChanged, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, IVisualElementController, IElementController, IView, ITransform, IElement, IVisualTreeElement, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISkiaGestureListener, IHasAfterEffects, ISkiaControl, IDrawnBase, ICanBeUpdatedWithContext, ICanBeUpdated, ISkiaDisposable, IDisposable
- Inheritance
-
SkiaSprite
- Implements
- Inherited Members
- Extension Methods
Constructors
SkiaSprite()
For standalone use
public SkiaSprite()
SkiaSprite(SkiaImage)
For building custom controls
public SkiaSprite(SkiaImage display)
Parameters
displaySkiaImageExisting SkiaImage to use for display
Fields
AnimationNameProperty
Bindable property for AnimationName
public static readonly BindableProperty AnimationNameProperty
Field Value
CachedSpriteSheets
Cache for loaded spritesheets to avoid reloading the same image multiple times
public static ConcurrentDictionary<string, SKBitmap> CachedSpriteSheets
Field Value
ColumnsProperty
Bindable property for Columns
public static readonly BindableProperty ColumnsProperty
Field Value
CurrentFrameProperty
Bindable property for CurrentFrame
public static readonly BindableProperty CurrentFrameProperty
Field Value
FrameSequenceProperty
Bindable property for FrameSequence
public static readonly BindableProperty FrameSequenceProperty
Field Value
FramesPerSecondProperty
Bindable property for FramesPerSecond
public static readonly BindableProperty FramesPerSecondProperty
Field Value
MaxFramesProperty
Bindable property for MaxFrames
public static readonly BindableProperty MaxFramesProperty
Field Value
RegisteredAnimations
Dictionary of named animation sequences that can be reused
public static ConcurrentDictionary<string, int[]> RegisteredAnimations
Field Value
RowsProperty
Bindable property for Rows
public static readonly BindableProperty RowsProperty
Field Value
SourceProperty
Bindable property for Source
public static readonly BindableProperty SourceProperty
Field Value
Properties
AnimationName
Name of a predefined animation sequence to use
public string AnimationName { get; set; }
Property Value
Columns
Number of columns in the spritesheet
public int Columns { get; set; }
Property Value
CurrentFrame
Current frame being displayed
public int CurrentFrame { get; set; }
Property Value
Display
Internal SkiaImage control used to display the current frame
public SkiaImage Display { get; protected set; }
Property Value
DurationMs
Duration of the animation in milliseconds
public double DurationMs { get; protected set; }
Property Value
FrameDurationMs
Duration of each frame in milliseconds
public double FrameDurationMs { get; protected set; }
Property Value
FrameHeight
Height of each frame in pixels
public int FrameHeight { get; protected set; }
Property Value
FrameSequence
Optional custom sequence of frames to play from the spritesheet. If set, this overrides the default sequential frame playback.
public int[] FrameSequence { get; set; }
Property Value
- int[]
FrameWidth
Width of each frame in pixels
public int FrameWidth { get; protected set; }
Property Value
FramesPerSecond
Frames per second for the animation
public double FramesPerSecond { get; set; }
Property Value
MaxFrames
Maximum number of frames to use from the spritesheet (0 means use all)
public int MaxFrames { get; set; }
Property Value
Rows
Number of rows in the spritesheet
public int Rows { get; set; }
Property Value
Source
Source of the spritesheet image
public string Source { get; set; }
Property Value
SpriteSheet
The full sprite sheet bitmap
public SKBitmap SpriteSheet { get; protected set; }
Property Value
TotalFrames
Total number of frames in the spritesheet
public int TotalFrames { get; protected set; }
Property Value
Methods
ApplySpeed()
Applies the current speed ratio to the animator
protected override void ApplySpeed()
CheckCanStartAnimator()
Checks if the animator can start
protected override bool CheckCanStartAnimator()
Returns
- bool
True if animator can start
ClearCache()
Clears the spritesheet cache completely
public static void ClearCache()
CreateAnimationSequence(string, int[])
Creates a named animation from a frame sequence
public static int[] CreateAnimationSequence(string name, int[] frameSequence)
Parameters
Returns
- int[]
The frame sequence array
GetAnimatorParent()
Gets the parent control for animator operations
protected override SkiaControl GetAnimatorParent()
Returns
- SkiaControl
The control to use as animator parent
GetFrameNumberFromTime(double)
Gets frame number from time based on current frame rate
protected int GetFrameNumberFromTime(double msTime)
Parameters
msTimedoubleTime in milliseconds
Returns
- int
Frame number
InvalidateMeasure()
Updates the layout of the Display when measurement needs to be invalidated
protected override void InvalidateMeasure()
LayoutDisplay()
Updates the layout options for the Display based on auto-sizing settings
protected virtual void LayoutDisplay()
LoadLocalImageAsync(string)
Loads a spritesheet image from a local or embedded resource
public Task<SKBitmap> LoadLocalImageAsync(string source)
Parameters
sourcestringPath to the image
Returns
LoadSourceAsync(string)
Loads a spritesheet image from a source URL, using cache when available
public Task<SKBitmap> LoadSourceAsync(string source)
Parameters
sourcestringURL of the spritesheet
Returns
OnAnimatorInitializing()
Initializes the animator with the correct timing values
protected override void OnAnimatorInitializing()
OnAnimatorSeeking(double)
Called by Seek
protected override void OnAnimatorSeeking(double time)
Parameters
timedoubleTime position to seek to
OnAnimatorUpdated(double)
Invoked by internal animator
protected override void OnAnimatorUpdated(double value)
Parameters
valuedoubleCurrent animation time value
OnDisposing()
Handles cleanup when the control is being disposed
public override void OnDisposing()
Paint(DrawingContext)
This is the main drawing routine you should override to draw something. Base one paints background color inside DrawingRect that was defined by Arrange inside base.Draw. Pass arguments if you want to use some time-frozen data for painting at any time from any thread..
protected override void Paint(DrawingContext ctx)
Parameters
ctxDrawingContext
RecalculateFrames()
Recalculates frame information based on current properties
protected void RecalculateFrames()
ReloadSource()
Reloads the sprite sheet from the Source property
public virtual void ReloadSource()
RemoveFromCache(string)
Removes a specific item from the spritesheet cache
public static void RemoveFromCache(string key)
Parameters
keystringThe source key to remove
RenderFrame(DrawingContext)
Renders the current frame of the animation
protected override void RenderFrame(DrawingContext ctx)
Parameters
ctxDrawingContextDrawing context
SetCurrentFrame(int)
Sets the current frame and updates the display
protected void SetCurrentFrame(int frameNumber)
Parameters
frameNumberintFrame number to display
SetSpriteSheet(SKBitmap, bool)
Sets the sprite sheet bitmap and initializes the animation
public void SetSpriteSheet(SKBitmap bitmap, bool disposePrevious)
Parameters
Start(int)
Starts the animation with optional delay
public override void Start(int delayMs = 0)
Parameters
delayMsintDelay in milliseconds before starting
Update()
Main method to invalidate cache and invoke rendering
public override void Update()