XEN0 -5 Newbie Poster

Ok here is the deal,i thought ImageAnimator can be controlled so im trying to do so by using the form Key Down Event,a timer,and an integer.So it fails with a
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll

Additional information: A generic error occurred in GDI+.
When i move the sprite starts to animate then throws a "Generic error".Also while im on the subject of animating i also need to know how to make form no flicker when animate kk? Any enlightening ideas?

Imports System
    Imports System.Text
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Drawing.Drawing2D
    Imports System.Collections.Generic
    Imports WindowsApplication32.libZPlay
    Public Class Form1
        Private zPlay As libZPlay.ZPlay
        Private gfx As Graphics
        Private playerRec As Rectangle
        Private playerBMP As Bitmap
        Private playerpoint As Point
        Dim anotherPoint As Point
        Dim anotherPoint0 As Point
        Friend currentFrame As Integer = 0
        Friend lastFrame As Integer
        Friend imgani As ImageAnimator
        Friend currentlyAnimating As Boolean = False
        Friend img As Image
        Friend dbgfx As BufferedGraphicsManager
        Friend aniDictionary As Dictionary(Of String, Rectangle)
        Public Sub AnimateImage()
            If Not currentlyAnimating Then
                ImageAnimator.Animate(playerBMP, New EventHandler(AddressOf Me.onFrameChanged))
                currentlyAnimating = True
            End If
        End Sub
        Public Sub stopanimate()
        End Sub
        Public Sub onFrameChanged()



        Me.Invalidate()
    End Sub
    Private Sub Initialize()
        playerBMP = New Bitmap("Resources/mc000.gif")
        playerpoint.X = 200
        playerpoint.Y = 200
        anotherPoint.X = 100
        anotherPoint.Y = 0
        anotherPoint0.X = 150
        anotherPoint0.Y = 50
        img = playerBMP
        aniDictionary = New Dictionary(Of String, Rectangle)
        playerBMP.SetResolution(90, 90)
        Timer1.Enabled = True
        Timer1.Interval = 1000
        Timer1.Start()
        zPlay = New ZPlay()
        zPlay.OpenFile("Resources/undergroundcavern.mp3", TStreamFormat.sfAutodetect)
    End Sub
    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        Try
            If e.KeyValue = 37 Then

                playerpoint.X -= 1
                currentFrame += 1
                If currentlyAnimating = False Then
                    If currentFrame > 2 Then
                        currentFrame = 0
                    End If
                End If
                If e.KeyValue = 13 Then
                    anotherPoint.X += 10
                    anotherPoint.Y += 10
                    anotherPoint0.X += 10
                    anotherPoint0.X += 10
                End If

            End If
            If e.KeyValue = 96 Then
                currentlyAnimating = True
            End If
        Catch ex As System.Runtime.InteropServices.ExternalException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "A Digital Whirlwind")
        End Try
        Me.Invalidate()
    End Sub
    Private Sub Form1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
        currentlyAnimating = True

    End Sub
    Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp

    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Initialize()
        zPlay.StartPlayback()
        currentlyAnimating = True
    End Sub
    Friend Sub playercontrol()

    End Sub
    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        gfx = e.Graphics
        gfx.Clear(Color.Black)
        AnimateImage()
        ImageAnimator.UpdateFrames(playerBMP)
        gfx.DrawImage(playerBMP, playerpoint.X, playerpoint.Y, img.Width, img.Height)
        gfx.DrawRectangle(Pens.White, New Rectangle(playerpoint.X, playerpoint.Y, 32, 32))
        Dim rec As Rectangle = Me.ClientRectangle
        gfx.DrawRectangle(Pens.White, rec)


        gfx.DrawString("Many moons ago,a demon was grown from the ground.Not just any demon he has been marked with the sign of darkness.", New Font("Tahoma", 8), Brushes.BlanchedAlmond, anotherPoint)
        gfx.DrawString("He feeds on the souls of the banished.", New Font("Tahoma", 8), Brushes.BlanchedAlmond, anotherPoint0)
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        playerBMP.SelectActiveFrame(FrameDimension.Time, currentFrame)
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.