Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Simple Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 05-17-2005, 05:05 PM
TwigX TwigX is offline
Newcomer
 
Join Date: May 2005
Posts: 6
Default Simple Problem


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:
Code:
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.
Reply With Quote
  #2  
Old 05-17-2005, 05:14 PM
webbone's Avatar
webbone webbone is offline
Hydrogen Powered

Administrator
* Expert *
 
Join Date: Jul 2003
Location: Sacramento, CA
Posts: 6,090
Default

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:
Code:
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
__________________
"With the appearance of the AddressOf operator, an entire industry has developed among authors illustrating how to do previously impossible tasks using Visual Basic. Another industry is rapidly developing among consultants helping users who have gotten into trouble attempting these tasks." -Dan Appleman
Reply With Quote
  #3  
Old 05-17-2005, 05:17 PM
TwigX TwigX is offline
Newcomer
 
Join Date: May 2005
Posts: 6
Default

I knew it wasnt hard to figure out, thanks a bunch
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->