Question How to Animate More than 2 pictures?

Kenta

Member
Joined
Mar 17, 2012
Messages
21
Programming Experience
Beginner
Hello ^^,

I want to make an animation of a Robotic Arm that picks something up...
I have wrote this code based on a tutorial.


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If cycle Mod 2 = 0 Then
Me.PictureBox1.Image = My.Resources.arm_initial
Else
Me.PictureBox1.Image = My.Resources.arm_leaned
End If
If flip = True Then
Me.PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
End If
Me.PictureBox1.Left = Me.PictureBox1.Left + x
Me.PictureBox1.Top = Me.PictureBox1.Top + y
cycle += 1
End Sub


Now this code is only for 2 pictures and I want to use 6 pictures for the animation. Can anyone help me to do that?
 
Hello ^^,

I want to make an animation of a Robotic Arm that picks something up...
I have wrote this code based on a tutorial.


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If cycle Mod 2 = 0 Then
Me.PictureBox1.Image = My.Resources.arm_initial
Else
Me.PictureBox1.Image = My.Resources.arm_leaned
End If
If flip = True Then
Me.PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
End If
Me.PictureBox1.Left = Me.PictureBox1.Left + x
Me.PictureBox1.Top = Me.PictureBox1.Top + y
cycle += 1
End Sub


Now this code is only for 2 pictures and I want to use 6 pictures for the animation. Can anyone help me to do that?

Hello

If you want to use 6 pictures for a better animation then I would suggest Select Case this will give you as many as you want, IE:

Select Case cycle
Case 1​
PictureBox1.Image = My.Resources.arm_initial​
Case 2​
PictureBox1.Image = My.Resources.arm_leaned​
Case 3​
'The next image..​
Case 4​
'The next image..​
Case 5​
'The next image..​
Case 6​
'The next image..
'Reset cycle to 1 for the first image..
cycle = 1​
End Select

By the way if you coding on the form that the picturebox is on you don't need to put me.picturebox it can just be PictureBox1 as in the above code.

regards
 
Hello

If you want to use 6 pictures for a better animation then I would suggest Select Case this will give you as many as you want, IE:

Select Case cycle
Case 1​
PictureBox1.Image = My.Resources.arm_initial​
Case 2​
PictureBox1.Image = My.Resources.arm_leaned​
Case 3​
'The next image..​
Case 4​
'The next image..​
Case 5​
'The next image..​
Case 6​
'The next image..
'Reset cycle to 1 for the first image..
cycle = 1​
End Select

By the way if you coding on the form that the picturebox is on you don't need to put me.picturebox it can just be PictureBox1 as in the above code.

regards


appreciate your try to assist but T_T it's not moving a bit now!! before it was two pics and now nothing! have an idea about it??
 
so the following is animating the pictures I wanted ... But now the problem is that after the first time of movement the sequence of pictures it changes!How can I fix that??

Appreciate the quick responds ^^..

VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If cycle Mod 10 = 0 Then
            Me.PictureBox1.Image = My.Resources._2
        ElseIf cycle Mod 8 = 0 Then
            Me.PictureBox1.Image = My.Resources._3
        ElseIf cycle Mod 6 = 0 Then
            Me.PictureBox1.Image = My.Resources._4
        ElseIf cycle Mod 3 = 0 Then
            Me.PictureBox1.Image = My.Resources._5
        End If

        If flip = True Then
            Me.PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
        End If
        Me.PictureBox1.Left = Me.PictureBox1.Left + x
        Me.PictureBox1.Top = Me.PictureBox1.Top + y
        cycle += 1
    End Sub
 
so the following is animating the pictures I wanted ... But now the problem is that after the first time of movement the sequence of pictures it changes!How can I fix that??

Appreciate the quick responds ^^..

VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If cycle Mod 10 = 0 Then
            Me.PictureBox1.Image = My.Resources._2
        ElseIf cycle Mod 8 = 0 Then
            Me.PictureBox1.Image = My.Resources._3
        ElseIf cycle Mod 6 = 0 Then
            Me.PictureBox1.Image = My.Resources._4
        ElseIf cycle Mod 3 = 0 Then
            Me.PictureBox1.Image = My.Resources._5
        End If

        If flip = True Then
            Me.PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
        End If
        Me.PictureBox1.Left = Me.PictureBox1.Left + x
        Me.PictureBox1.Top = Me.PictureBox1.Top + y
        cycle += 1
    End Sub

I assume that you have the first picture loaded into the object on startup. Well this code will only cycle through number 2,3,4,5 and never put number 1 in so the sequence will change because of that. Why not use the select case as I have shown (this is a much neater way of doing what you want to do), is cycle used somewhere else and if not why not reset it as shown in the code I gave you.

I am not sure why you are using mod for the cycle number, surely this will have a strange affect on the timing because you are adding 1 so there are 10 potentials to cycle through when you have 5.

One other thing as I said before you don't need to use Me.PictureBox1 when calling from the form that it is on you can just refer to it as PictureBox1.
 
I was wondering about the MOD as well.. Since anything integer-divisible by 10 will ALSO be by 5 and 2, I'm guessing that's not what you really want to do.
 
Well, I didn't use the Select statement because it's not moving at all like I have posted the reply UP . I tried everything with it. Besides I agree with you about the "Me." it's just not affecting anything that's why I didn't remove it ><" . What comes about the MOD I have no idea about it :uhh: I just found it in a YouTube vid of how to move a Bat... no explanation just the applying...
 
Well, I didn't use the Select statement because it's not moving at all like I have posted the reply UP . I tried everything with it. Besides I agree with you about the "Me." it's just not affecting anything that's why I didn't remove it ><" . What comes about the MOD I have no idea about it :uhh: I just found it in a YouTube vid of how to move a Bat... no explanation just the applying...

I am not 100% sure what your first sentence means, do you mean the select statement did not work? If so then the reason why is because I gave you an idea of how to apply the code but not the actual code. All you have to do is apply the idea to your program not using mod but having a counter starting at 1 and incrementing by 1 each time the timer is activated, put your pictures in the select case statement however many there are, reset the counter to 1 when you reach the last picture and badda bing, it should work. If not put the select case code up here for me to have a look at.
 
Back
Top