Simple Problem

TwigX
05-17-2005, 06:05 PM
Im working on a small RPG and its been awhile since Ive worked with VB and I seem to be rusty. Im trying to make an image (IMGSelf) to change its .Picture property between 3 different images on keydown. Harder to explain, but maybe the code can help:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If IMGSelf.Picture = IMGwalk(0).Picture Then
IMGSelf.Picture = IMGwalk(1).Picture
End If
If IMGSelf.Picture = IMGwalk(1).Picture Then
IMGSelf.Picture = IMGwalk(2).Picture
End If
If IMGSelf.Picture = IMGwalk(2).Picture Then
IMGSelf.Picture = IMGwalk(0).Picture
End If
If KeyCode = vbKeyUp Then
IMGSelf.Top = IMGSelf.Top - 435
End If
If KeyCode = vbKeyDown Then
IMGSelf.Top = IMGSelf.Top + 435
End If
If KeyCode = vbKeyLeft Then
IMGSelf.Left = IMGSelf.Left - 300
End If
If KeyCode = vbKeyRight Then
IMGSelf.Left = IMGSelf.Left + 300
End If


End Sub


Private Sub Form_Load()
IMGSelf.Picture = IMGwalk(0).Picture

End Sub

As you can see, Im trying to make it check to see what picture it is using on every keydown, and then rotate to the next one. Heres a screenshot if it helps anything:
http://img283.echo.cx/img283/9774/snap00857sy.jpg
Thanks in advance.

webbone
05-17-2005, 06:14 PM
You probably just want to use either a global variable or a local, static variable to retain your pointer to which picture is being used. An example might be:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Static iImgPtr as Integer 'will be initialized to 0 on the first call to this routine!

iImgPtr = (iImgPtr + 1) Mod 3 'this will make iImgPtr sequence 0,1,2,0,1...
IMGSelf.Picture = IMGwalk(iImgPtr).Picture 'update yourself with new image

If KeyCode = vbKeyUp Then
IMGSelf.Top = IMGSelf.Top - 435
End If
If KeyCode = vbKeyDown Then
IMGSelf.Top = IMGSelf.Top + 435
End If
If KeyCode = vbKeyLeft Then
IMGSelf.Left = IMGSelf.Left - 300
End If
If KeyCode = vbKeyRight Then
IMGSelf.Left = IMGSelf.Left + 300
End If


End Sub

TwigX
05-17-2005, 06:17 PM
I knew it wasnt hard to figure out, thanks a bunch :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum