|
-
Oct 21st, 2000, 04:53 PM
#1
Thread Starter
Frenzied Member
This is what I have...if you look at it carefully, you will see, every time you push the button, the "animation" goes, but it slows the whole program, can I make it only slow down that sub?
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'CHecks keypresses
If KD(vbKeyLeft) = True Then
Player.x = Player.x - 1
Player2.x = Player.x
Player.DC = picPlayer2.hDC
If Player.x < 0 Then: Player.x = 0
End If
If KU(vbKeyLeft) = True Then
Call Skate(False)
End If
Private Sub Skate(ifSkate As Boolean)
'makes the guy skate
Do Until ifSkate = False
If SkateVar = 1 Then Player.DC = picPlayer.hDC
If SkateVar = -1 Then Player.DC = picPlayer2.hDC
Sleep (100)
SkateVar = Val(SkateVar) * (-1)
ifSkate = False
Loop
End Sub
thanks all 
-
Oct 21st, 2000, 05:12 PM
#2
transcendental analytic
That depends what you mean with slow down, sleep function pauses the app completely, you can't do something like "just pause that sub" because vb doesn't support multithreading. On the other hand i think you can have a loop waiting for the specific amount of time while allowing other events to fire, if that's what you want.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 21st, 2000, 06:11 PM
#3
Thread Starter
Frenzied Member
How would I have a loop wait for a certain amount of time? Just set a for loop so a high number?
-
Oct 21st, 2000, 07:30 PM
#4
transcendental analytic
Actually, I think what you need is a sub that loops until a specified amount t time in milliseconds have passed:
Code:
Declare Function GetTickCount Lib "kernel32" () As Long
Sub Dealy(t As Long): Dim b As Long
b = t + GetTickCount
Do Until t < GetTickCount
DoEvents
Loop
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 21st, 2000, 10:37 PM
#5
Thread Starter
Frenzied Member
Sorry, my fault, I didn't explain myself enough. When I put your code in everything works fine, the player moves the right speed, but my animation doesn't...it goes too fast.
Would there be a way to make the animation in that function so after a certain amount of time it changes the animation?
[Edited by SteveCRM on 10-21-2000 at 11:43 PM]
-
Oct 21st, 2000, 11:05 PM
#6
DoEvents, Steve.
And if it still moves to fast, place a sleep event before the DoEvents.
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'CHecks keypresses
If KD(vbKeyLeft) = True Then
Player.x = Player.x - 1
Player2.x = Player.x
Player.DC = picPlayer2.hDC
If Player.x < 0 Then: Player.x = 0
End If
If KU(vbKeyLeft) = True Then
Call Skate(False)
End If
Private Sub Skate(ifSkate As Boolean)
'makes the guy skate
Do Until ifSkate = False
If SkateVar = 1 Then Player.DC = picPlayer.hDC
If SkateVar = -1 Then Player.DC = picPlayer2.hDC
Sleep (100 )
SkateVar = Val(SkateVar) * (-1)
ifSkate = False
DoEvents
Loop
End Sub
-
Oct 21st, 2000, 11:07 PM
#7
Thread Starter
Frenzied Member
But the problem with having the sleep is that it makes it so the player moves forward slower...I hope you understand what I mean, If you want me too, I can upload the form and module.
-
Oct 21st, 2000, 11:12 PM
#8
I think I understand. You are saying that without a little timer/sleep, the animation is to fast. But with it, the player moves to damn slow. <- that what you mean?
I see you have 100, did you try changing it? To 50 or something?
[Edited by Matthew Gates on 10-22-2000 at 12:15 AM]
-
Oct 21st, 2000, 11:18 PM
#9
Thread Starter
Frenzied Member
thats it, but when its turned down, the animation goes too fast This is frustrating...but thanks for all the hlep you guys are giving me!
-
Oct 22nd, 2000, 04:27 AM
#10
transcendental analytic
Hey folks! Don't use sleep when you already have a loop with doevents, it's like having two cakes on one birthday party or something... At least sleep is not the right one.
Code:
Private Sub Skate(ifSkate As Boolean)
'makes the guy skate
Do Until ifSkate = False
If SkateVar = 1 Then Player.DC = picPlayer.hDC
If SkateVar = -1 Then Player.DC = picPlayer2.hDC
Dealy 100
SkateVar = Val(SkateVar) * (-1)
ifSkate = False
Loop
End Sub
What you do is replace the sleep call with Dealy instead, now if it goes too slow or too fast you just change the amount of milliseconds to pass on Dealy.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|