Jump to content
  • Advertisement
Sign in to follow this  
ferr

[.net] C# 2D Img Animation - Current Frame Lookup

This topic is 4417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I have a .gif animation that is 30 frames in length, I would like very much to be able to play the animation from frame 1 and stop when it reaches 30. The problem is, I can't seem to find anything that actually gives information about the current frame that is being rendered. Currently, the only way I've found to stop the animation at an appropriate time is to use a timer (i.e. if an animation is about 3 seconds long, use a timer that ticks every 3000ms to disable an animation). Problem with this is, if for some reason the animation lags, even in the slightest, it will stop before the final frame, and this isn't satisfactory. BTW, I am using the System.Drawing.ImageAnimator class to animate. Is there an alternative MDX class with more functionality that might help, or is this doable with ImageAnimator?

Share this post


Link to post
Share on other sites
Advertisement
When you call Animate on the object, you pass it an event handler for the FrameChanged event. Track the current frame there and stop the animation when needed.


Private animatedImage As New Bitmap("Grammar.gif")
Private currentlyAnimating As Boolean = False
Private frameNum As Integer

Public Sub AnimateImage()
If Not currentlyAnimating Then

'Begin the animation only once.
ImageAnimator.Animate(animatedImage, _
New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
frameNum = 1
End If
End Sub

Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)

'Force a call to the Paint event handler.
Me.Invalidate()
frameNum += 1
If frameNum = 82 Then ImageAnimator.StopAnimate(animatedImage, AddressOf Me.OnFrameChanged)


End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

'Begin the animation.
AnimateImage()

'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames()

'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0))
End Sub

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!