So I have a project that utilizes a Timer control and an image stored in a resource file.
The Resource file is an image that's 6144 x 768.
I have a string of code that sets a Step variable from 1 to 6.
When the Timer control fires, it takes the image, crops it so only part of it is displayed, then calls the form's Paint event.
The Timer then increments the Step variable by 1, once it gets to 6, the variable is reset.
In this way I've created an animation loop.
Everything works great- except that no matter what the Interval on the Timer control is set to, the animation itself is very, very slow. There's no flickering, no stuttering. It runs at what appears to be a constant speed- it just needs to be... faster, I guess.
What would you suggest as a better alternative to the standard Timer control for this particular purpose?
The user needs to see the animation happening and it runs in a loop, so I don't think a Do While is the answer here.
What I have tried:
This is the code for the paint operation that puts the image on the screen without flickering-
private void FormPaint(object MainScreen, PaintEventArgs e)
{
var g = e.Graphics;
Bitmap TransferBitmap = new Bitmap(AnimationProject.Properties.Resources.Title);
RectangleF cloneRect = new RectangleF(Global.AnimationPosition, 0, 1064, 768);
System.Drawing.Imaging.PixelFormat format = TransferBitmap.PixelFormat;
Bitmap cloneBitmap = TransferBitmap.Clone(cloneRect, format);
g.DrawImage(cloneBitmap, 0, 0, (this.Width + 60), this.Height);
}
And this is the code that the Timer fires off-
private void TitleTimer_Tick(object sender, EventArgs e)
{
this.Invalidate();
int InterVal = ((AnimationProject.Properties.Resources.Fan.Width) / 1024) - 1;
if (Global.AnimationCounter < InterVal)
{
Global.AnimationPosition = Global.AnimationPosition + 1024;
Global.AnimationCounter++;
}
if (Global.AnimationCounter == InterVal)
{
Global.AnimationPosition = 0;
Global.AnimationCounter = 0;
}
}