6 Replies - 334 Views - Last Post: 27 February 2018 - 11:28 AM Rate Topic: -----

#1 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Animation Movement?

Posted 26 February 2018 - 03:09 PM

I have a picture box with an image of a man walking this works fine while the picture box is not moving.But when I move the the picture box the animation stops, how do I move the picture box and keep the animation image walking?
Is This A Good Question/Topic? 0
  • +

Replies To: Animation Movement?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14092
  • View blog
  • Posts: 56,460
  • Joined: 12-June 08

Re: Animation Movement?

Posted 26 February 2018 - 03:15 PM

What is the animation file type?
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5225
  • View blog
  • Posts: 14,005
  • Joined: 18-April 07

Re: Animation Movement?

Posted 26 February 2018 - 03:16 PM

I don't see why the picturebox moving would cancel out the changing of the image. Got any code to show us? Ideally you would move the box on each update cycle as you update the image.
Was This Post Helpful? 0
  • +
  • -

#4 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Re: Animation Movement?

Posted 26 February 2018 - 03:50 PM

It's a gif image, code below

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        PictureBox1.Image = My.Resources.walkingRight
        PictureBox1.Left = PictureBox1.Left + 10

    End Sub

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        Timer1.Enabled = True
    End Sub


Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14092
  • View blog
  • Posts: 56,460
  • Joined: 12-June 08

Re: Animation Movement?

Posted 26 February 2018 - 03:52 PM

What you should be doing is doing the 'animation' yourself. Having individual stills you are flipping based on time and order. What I am guessing is the control's gif has to restart each time the form is refreshed/updated and until that movement ends it is stuck at restarting.
Was This Post Helpful? 2
  • +
  • -

#6 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1499
  • View blog
  • Posts: 3,797
  • Joined: 01-February 13

Re: Animation Movement?

Posted 27 February 2018 - 10:45 AM

This is a common problem with using animated gif images in a PictureBox, sometimes they animate and sometimes they don't. There is nothing you can do to make the animation work reliably other than what modi123_1 has said, do the animation yourself.

You can do that by programmatically stripping all the frames/images from the Gif file along with each frame's delay time and store each frame and it's delay in a small Class. Keep them in a List(Of Your Class). Then you can just use a Timer to control the animation of each frame. I have posted an example of doing all this in the link below where I helped someone else with a similar gif animation problem.

Too slow gif

Doing it this way, you can control the animation however you want. Start/Stop the animation when the game character starts/stops moving, modify the timing of the frame delays to make the animation faster/slower, or even play the animation in reverse if you want.

However, do be aware that you don't want to get into the habit of using a PictureBox or any other controls for game characters. All the images for the game should be drawn directly on the Form by using the Form's Paint Event and the Graphics Class that is passed to it in the e parameter. The Graphics class has a lot of methods for drawing images and shapes. There should be no controls involved.

Below are a few links that can help get you started in the right direction for creating games in Vb.Net. The first link is just for getting the hang of drawing a game character image on the form and moving it around using the 4 arrow keys. The second link is a little more advanced but, shows the concept of how a game should be put together, using classes for the game objects. The last link is something that a friend of mine just put on github for creating games in Vb.Net applications.

Drawing and moving a game sprite image on a form
OOP with Video Game Basics Part 1
How To: Get Started with Video Game Development in Visual Basic .Net using the PuppyBreath framework.
Was This Post Helpful? 2
  • +
  • -

#7 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Re: Animation Movement?

Posted 27 February 2018 - 11:28 AM

Thanks for the replies, I'm not trying to do anything in particular just wanted to see if I could get an animated figure from one side of the form to the other.
But now I have some examples and links I might try some kind of simple game?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1