Visual basic 2008 moving animations

need help on moving pictures with different frames

Page 1 of 1

10 Replies - 16653 Views - Last Post: 23 November 2010 - 09:38 PM Rate Topic: -----

#1 senister8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-July 09

Visual basic 2008 moving animations

Post icon  Posted 27 July 2009 - 02:18 PM

So far i have tried to animate the pictures and it works but could not move with keydown event. I also then tried a different way and managed to move the first picture by using drawimage but could not animate it in frames. Any Ideas?
Is This A Good Question/Topic? 0
  • +

Replies To: Visual basic 2008 moving animations

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual basic 2008 moving animations

Posted 27 July 2009 - 02:20 PM

You say you tried a couple things, show us the code you've tried so far :)
Was This Post Helpful? 0
  • +
  • -

#3 senister8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-July 09

Re: Visual basic 2008 moving animations

Posted 27 July 2009 - 02:38 PM

View PostPsychoCoder, on 27 Jul, 2009 - 01:20 PM, said:

You say you tried a couple things, show us the code you've tried so far :)


Public Class test
Dim picture1 As String = ("C:/Users/Owner/Documents/Downloads/bfly1.gif")
Dim mygrapics As Graphics


 Private Sub test_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

		Select Case e.KeyCode


			'key move right'
			Case Keys.Right
				mygrapics.Clear(Me.BackColor)
				mygrapics.DrawImage(PictureBox1.Image, thelocation.X, thelocation.Y, 52, 50)
				thelocation.X += 10
			   


				'key move left'
			Case Keys.Left
				thelocation.X -= 10
				mygrapics.Clear(Me.BackColor)
				mygrapics.DrawImage(PictureBox1.Image, thelocation.X, thelocation.Y, 52, 50)

				'key move up'
			Case Keys.Up
				mygrapics.Clear(Me.BackColor)
				mygrapics.DrawImage(PictureBox1.Image, thelocation.X, thelocation.Y, 52, 50)
				thelocation.Y -= 10

				'key move down'
			Case Keys.Down
				mygrapics.Clear(Me.BackColor)
				mygrapics.DrawImage(PictureBox1.Image, thelocation.X, thelocation.Y, 52, 50)
				thelocation.Y += 10

		End Select

	  End Sub

Private Sub test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		mygrapics = Me.CreateGraphics
		thelocation.X = 347	
		thelocation.Y = 152   


this is basically how i moved the picture:

 Private Sub test_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

 If picturebox1.visible = true then
picturebox1.visible = false
picturebox2.visible = true

elself  picturebox2.visible = true then
picturebox2.visible = false
picturebox3.visible = true 

(the rest is same all the way to eight )

..... elself picturebox8.visible = true then
picturebox8.visible = false
picturebox1.visible = true
end if 



They both work and btw im using visual basic 2008

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#4 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: Visual basic 2008 moving animations

Posted 27 July 2009 - 05:44 PM

Okay, so you're trying to let the user move an animated image across the form is that it?
I just don't understand your second version of the KeyDown event handler and all the picture boxes. You could theoretically do just just by moving the picture box, or you could draw on the form and there are a few tips I can give you for that. If you don't need or plan on using the picture box there is instead just the Image class, you can just load the image into a variable which is pretty much what PictureBox does but in your case we need to draw it ourselves using the controls Graphics object. First of all, and especially because we're planning on using an animated image and moving it around, you should set the DoubleBuffered property of the control to True. You can learn more about double buffering here.
I would also advise against using Me.CreateGraphics for these purposes and instead handle the controls Paint event or override the OnPaint method and use the graphics property of it's PaintEventArgs, (e.Graphics). You still use the KeyDown event to change the location value, but do all the drawing in Form_Paint or OnPaint. So it might look roughly like:
 Private Sub test_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

		Select Case e.KeyCode
			'key move right'
			Case Keys.Right
				thelocation.X += 10
				Me.Invalidate
				'key move left'
			Case Keys.Left
				thelocation.X -= 10
				Me.Invalidate()
				'key move up'
			Case Keys.Up
				thelocation.Y -= 10
				Me.Invalidate()
				'key move down'
			Case Keys.Down
				thelocation.Y += 10
				Me.Invalidate()
		End Select
	  End Sub

	Private Sub test_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
		e.Graphics.Clear(Me.BackColor)
		e.Graphics.DrawImage(myImage, thelocation.X, thelocation.Y, 52, 50)
	End Sub


Was This Post Helpful? 1
  • +
  • -

#5 senister8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-July 09

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 04:38 AM

View PostLoveIsNull, on 27 Jul, 2009 - 04:44 PM, said:

Okay, so you're trying to let the user move an animated image across the form is that it?
I just don't understand your second version of the KeyDown event handler and all the picture boxes. You could theoretically do just just by moving the picture box, or you could draw on the form and there are a few tips I can give you for that. If you don't need or plan on using the picture box there is instead just the Image class, you can just load the image into a variable which is pretty much what PictureBox does but in your case we need to draw it ourselves using the controls Graphics object. First of all, and especially because we're planning on using an animated image and moving it around, you should set the DoubleBuffered property of the control to True. You can learn more about double buffering here.
I would also advise against using Me.CreateGraphics for these purposes and instead handle the controls Paint event or override the OnPaint method and use the graphics property of it's PaintEventArgs, (e.Graphics). You still use the KeyDown event to change the location value, but do all the drawing in Form_Paint or OnPaint. So it might look roughly like:
 Private Sub test_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

		Select Case e.KeyCode
			'key move right'
			Case Keys.Right
				thelocation.X += 10
				Me.Invalidate
				'key move left'
			Case Keys.Left
				thelocation.X -= 10
				Me.Invalidate()
				'key move up'
			Case Keys.Up
				thelocation.Y -= 10
				Me.Invalidate()
				'key move down'
			Case Keys.Down
				thelocation.Y += 10
				Me.Invalidate()
		End Select
	  End Sub

	Private Sub test_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
		e.Graphics.Clear(Me.BackColor)
		e.Graphics.DrawImage(myImage, thelocation.X, thelocation.Y, 52, 50)
	End Sub



Thanks for tip! :) What i really wanna know is how to make it move and animate it in different frames.
I use 8 pictures and named it picturebox1,picturebox2, ect.
Was This Post Helpful? 0
  • +
  • -

#6 bflosabre91  Icon User is offline

  • D.I.C Lover

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 05:58 AM

there are much better means of animation in WPF applications. maybe check that out if this isnt working that well for you.

http://msdn.microsof...y/ms752312.aspx

This post has been edited by bflosabre91: 28 July 2009 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#7 senister8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-July 09

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 06:14 AM

View Postbflosabre91, on 28 Jul, 2009 - 04:58 AM, said:

there are much better means of animation in WPF applications. maybe check that out if this isnt working that well for you.

http://msdn.microsof...y/ms752312.aspx

What im trying to do is create a game using visual basic and right now im working on moving the character. After I get this part down im going into collision. Im having trouble with sites because most are outdated.
Was This Post Helpful? 0
  • +
  • -

#8 bflosabre91  Icon User is offline

  • D.I.C Lover

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 08:34 AM

View Postsenister8, on 28 Jul, 2009 - 09:14 AM, said:

View Postbflosabre91, on 28 Jul, 2009 - 04:58 AM, said:

there are much better means of animation in WPF applications. maybe check that out if this isnt working that well for you.

http://msdn.microsof...y/ms752312.aspx

What im trying to do is create a game using visual basic and right now im working on moving the character. After I get this part down im going into collision. Im having trouble with sites because most are outdated.


have you looked into XNA? I'm not saying u cant make a game in vb, but thats not what its really meant for.

http://creators.xna..../gettingstarted
Was This Post Helpful? 0
  • +
  • -

#9 senister8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-July 09

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 10:54 AM

View Postbflosabre91, on 28 Jul, 2009 - 07:34 AM, said:

View Postsenister8, on 28 Jul, 2009 - 09:14 AM, said:

View Postbflosabre91, on 28 Jul, 2009 - 04:58 AM, said:

there are much better means of animation in WPF applications. maybe check that out if this isnt working that well for you.

http://msdn.microsof...y/ms752312.aspx

What im trying to do is create a game using visual basic and right now im working on moving the character. After I get this part down im going into collision. Im having trouble with sites because most are outdated.


have you looked into XNA? I'm not saying u cant make a game in vb, but thats not what its really meant for.

http://creators.xna..../gettingstarted

Well im not just trying to make a game at this point but trying to get used to programming because as you can see im a beginner. I need to get used to the codes and programming.
Was This Post Helpful? 0
  • +
  • -

#10 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: Visual basic 2008 moving animations

Posted 28 July 2009 - 05:17 PM

You can animate the image yourself by using a timer or separate thread. Get the number of frames in the image, in the timer use SelectActiveFrame.
Dim fDimension As New Imaging.FrameDimension(myImage.FrameDimensionsList(0))
Dim iFrames As Integer = myImage.GetFrameCount(fDimension) - 1
Dim iCurrentFrame As Integer = 0
Private Sub tmrAnim_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnim.Tick
	If iCurrentFrame = iFrames Then
		iCurrentFrame = 0
	End If
	iCurrentFrame += 1
	myImage.SelectActiveFrame(fDimension, iCurrentFrame)

	Me.Invalidate()
End Sub

Was This Post Helpful? 0
  • +
  • -

#11 Guest_Jonathan*


Reputation:

Re: Visual basic 2008 moving animations

Posted 23 November 2010 - 09:38 PM

View PostLoveIsNull, on 27 July 2009 - 04:44 PM, said:

Okay, so you're trying to let the user move an animated image across the form is that it?
I just don't understand your second version of the KeyDown event handler and all the picture boxes. You could theoretically do just just by moving the picture box, or you could draw on the form and there are a few tips I can give you for that. If you don't need or plan on using the picture box there is instead just the Image class, you can just load the image into a variable which is pretty much what PictureBox does but in your case we need to draw it ourselves using the controls Graphics object. First of all, and especially because we're planning on using an animated image and moving it around, you should set the DoubleBuffered property of the control to True. You can learn more about double buffering here.
I would also advise against using Me.CreateGraphics for these purposes and instead handle the controls Paint event or override the OnPaint method and use the graphics property of it's PaintEventArgs, (e.Graphics). You still use the KeyDown event to change the location value, but do all the drawing in Form_Paint or OnPaint. So it might look roughly like:
 Private Sub test_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

		Select Case e.KeyCode
			'key move right'
			Case Keys.Right
				thelocation.X += 10
				Me.Invalidate
				'key move left'
			Case Keys.Left
				thelocation.X -= 10
				Me.Invalidate()
				'key move up'
			Case Keys.Up
				thelocation.Y -= 10
				Me.Invalidate()
				'key move down'
			Case Keys.Down
				thelocation.Y += 10
				Me.Invalidate()
		End Select
	  End Sub

	Private Sub test_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
		e.Graphics.Clear(Me.BackColor)
		e.Graphics.DrawImage(myImage, thelocation.X, thelocation.Y, 52, 50)
	End Sub





i've tried the code you gave here, but how to move the 1 image without clearing the other image? in my case i use 1 line and 1 icon, i want the icon moves while the line is still there.. the code i tried is like this, its clear all the graphic available..

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

Public Class Form1




    Dim picture1 As Object

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

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Label1.Text = MousePosition.X
        Label2.Text = MousePosition.Y

        Dim pen1 As New System.Drawing.Pen(Color.Black, 1)
        Dim g As System.Drawing.Graphics
        Dim PingPos As Long
        PingPos = MousePosition.X + 150
        g = Me.CreateGraphics
        g.DrawArc(pen1, MousePosition.X, MousePosition.Y, 5, 5, 30, 30)

        Dim vehicle As New Icon("Goofy.ico", 2, 2)
        Dim d As System.Drawing.Graphics
        Dim icon1 As New System.Drawing.Icon(vehicle, 1, 1)
        d = Me.CreateGraphics
        d.Clear(Me.BackColor)
        d.DrawIcon(icon1, MousePosition.X, MousePosition.Y)

    End Sub

End Class



thank you..
Was This Post Helpful? 0

Page 1 of 1