Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Some newbie help here please
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RaLz




PostPosted: Wed May 12, 2004 4:16 pm   Post subject: Some newbie help here please

Hey im trying to make a game in vb and it's basically my first time trying to make on in vb. So i need some info. Right now im trying to make my character run across the screen but i have a problem if i hold down the arrow key and say i put a loop like this
"
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
Do Until KeyUp = 37
char.Left = char.Left - 10
loop
end if

the character just zooms across the screen and crashes vb. Now i was wondering if there is some delay command like in turing to slow this process down. If you guys have any suggestions on how to make this run smoothly it would be much appreaciated.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed May 12, 2004 4:24 pm   Post subject: (No subject)

well instead of -10, you could move by a smaller incroment... such as -0.1

or you could use a system delay which in VB is called sleep
code:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

and is called
code:

Sleep numMilliseconds

where numMilliseconds is an integer value of the delay in milliseconds
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
RaLz




PostPosted: Wed May 12, 2004 4:51 pm   Post subject: (No subject)

Thanks!!
RaLz




PostPosted: Wed May 12, 2004 5:05 pm   Post subject: (No subject)

umm here is my code for the moment how do i get the keyup function to work and by the way the sleep function works great.
code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
Do Until x = 20
char.Left = char.Left - 100
x = x + 1
Loop
ElseIf KeyCode = 39 Then
Do Until x = 20
char.Left = char.Left + 100
x = x + 1
Sleep (50)
Loop
End If
End Sub


I want to put do until keyup = 37 but it's not working because it sees keyup as just a variable.
RaLz




PostPosted: Wed May 12, 2004 5:31 pm   Post subject: (No subject)

Never mind i figured it out Wink
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: