Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. animation?

animation?

Scheduled Pinned Locked Moved Visual Basic
graphicsquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Wike
    wrote on last edited by
    #1

    Please tell me there is a better way to make a pacman like shape move across my form...

    Public Class Form1
    Dim formSurface As Graphics = Me.CreateGraphics
    Dim intLoop As Integer = 0

    Private Sub btnStart\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        tmrMove.Enabled = True
    End Sub
    
    Private Sub tmrMove\_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
    
    
        formSurface.Clear(Color.Black)
        Select Case intLoop
            Case 0
                formSurface.DrawImage(My.Resources.pacmanopen, 10, 75)
    
            Case 1
                formSurface.DrawImage(My.Resources.pacmanopen, 11, 75)
    
            Case 2
                formSurface.DrawImage(My.Resources.pacmanopen, 12, 75)
    
            Case 3
                formSurface.DrawImage(My.Resources.pacmanopen, 13, 75)
    
            Case 4
                formSurface.DrawImage(My.Resources.pacmanopen, 14, 75)
    
            Case 5
                formSurface.DrawImage(My.Resources.pacmanopen, 15, 75)
    
        End Select
        intLoop += 1
    End Sub
    

    End Class

    Could I possibly do something like...

            Case 0 to 100
                formSurface.DrawImage(My.Resources.pacmanopen, intX, 75)
    

    and then add 1 to intX each time? I'm open to any ideas...

    L C 2 Replies Last reply
    0
    • A Adam Wike

      Please tell me there is a better way to make a pacman like shape move across my form...

      Public Class Form1
      Dim formSurface As Graphics = Me.CreateGraphics
      Dim intLoop As Integer = 0

      Private Sub btnStart\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
          tmrMove.Enabled = True
      End Sub
      
      Private Sub tmrMove\_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
      
      
          formSurface.Clear(Color.Black)
          Select Case intLoop
              Case 0
                  formSurface.DrawImage(My.Resources.pacmanopen, 10, 75)
      
              Case 1
                  formSurface.DrawImage(My.Resources.pacmanopen, 11, 75)
      
              Case 2
                  formSurface.DrawImage(My.Resources.pacmanopen, 12, 75)
      
              Case 3
                  formSurface.DrawImage(My.Resources.pacmanopen, 13, 75)
      
              Case 4
                  formSurface.DrawImage(My.Resources.pacmanopen, 14, 75)
      
              Case 5
                  formSurface.DrawImage(My.Resources.pacmanopen, 15, 75)
      
          End Select
          intLoop += 1
      End Sub
      

      End Class

      Could I possibly do something like...

              Case 0 to 100
                  formSurface.DrawImage(My.Resources.pacmanopen, intX, 75)
      

      and then add 1 to intX each time? I'm open to any ideas...

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      yes, you should keep your shape's location in some variable(s). And paint only in the Paint handler. This article[^] will give you the principles and an example; it is a C# example, but that only constitutes a different syntax, it does not affect the principles. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read formatted code with indentation, so please use PRE tags for code snippets.


      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


      A 1 Reply Last reply
      0
      • A Adam Wike

        Please tell me there is a better way to make a pacman like shape move across my form...

        Public Class Form1
        Dim formSurface As Graphics = Me.CreateGraphics
        Dim intLoop As Integer = 0

        Private Sub btnStart\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            tmrMove.Enabled = True
        End Sub
        
        Private Sub tmrMove\_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
        
        
            formSurface.Clear(Color.Black)
            Select Case intLoop
                Case 0
                    formSurface.DrawImage(My.Resources.pacmanopen, 10, 75)
        
                Case 1
                    formSurface.DrawImage(My.Resources.pacmanopen, 11, 75)
        
                Case 2
                    formSurface.DrawImage(My.Resources.pacmanopen, 12, 75)
        
                Case 3
                    formSurface.DrawImage(My.Resources.pacmanopen, 13, 75)
        
                Case 4
                    formSurface.DrawImage(My.Resources.pacmanopen, 14, 75)
        
                Case 5
                    formSurface.DrawImage(My.Resources.pacmanopen, 15, 75)
        
            End Select
            intLoop += 1
        End Sub
        

        End Class

        Could I possibly do something like...

                Case 0 to 100
                    formSurface.DrawImage(My.Resources.pacmanopen, intX, 75)
        

        and then add 1 to intX each time? I'm open to any ideas...

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        The whole approach of using winforms is doomed to failure. You should use XNA, or perhaps WPF, something DirectX based.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        A F 2 Replies Last reply
        0
        • C Christian Graus

          The whole approach of using winforms is doomed to failure. You should use XNA, or perhaps WPF, something DirectX based.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          A Offline
          A Offline
          Adam Wike
          wrote on last edited by
          #4

          Sadly it's for a school project and I have to do it my teachers way...but I'll defiantely look into that stuff for future programs that I do on my own time.

          1 Reply Last reply
          0
          • L Luc Pattyn

            yes, you should keep your shape's location in some variable(s). And paint only in the Paint handler. This article[^] will give you the principles and an example; it is a C# example, but that only constitutes a different syntax, it does not affect the principles. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            A Offline
            A Offline
            Adam Wike
            wrote on last edited by
            #5

            Alright thanks I'll go look at it right now. I knew there was an easier way..

            1 Reply Last reply
            0
            • C Christian Graus

              The whole approach of using winforms is doomed to failure. You should use XNA, or perhaps WPF, something DirectX based.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              F Offline
              F Offline
              FeRtoll
              wrote on last edited by
              #6

              i agree! :P

              FeRtoll Software.net ------------ E-Mail me WebPage

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups