I'm trying to make a very basic animation with SkiaSharp in Xamarin. Basically a small point spinning in a circle.
A basic Timer
does the job, however i can't keep a consistent speed for the animation across different devices. The speed of the animation changes drastically based on the screen size (for example if i switch to Landscape the animation is about half as slow).
This is my code:
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
int width = e.Info.Width;
int height = e.Info.Height;
canvas.Translate(width / 2, height / 2);
canvas.Scale(0.2f, 0.2f);
canvas.Save();
float radiusDot = radius * 8;
canvas.DrawCircle((float)(radiusDot * Math.Sin(degree * (Math.PI / 180))), (float)(radiusDot * Math.Cos(degree * (Math.PI / 180))), 100, blueFillPoint);
canvas.Restore();
canvas.Save();
}
and the timers:
Device.StartTimer(TimeSpan.FromMilliseconds(5), () =>
{
if (degree == 0) degree = 360;
else degree -= 2;
if (degreeTail == 360) degreeTail = 0;
else degreeTail += 2;
return true;
});
Device.StartTimer(TimeSpan.FromSeconds(1f / 120), () =>
{
this.InvalidateSurface();
return true;
});