Results 1 to 10 of 10

Thread: Sleeping only 1 sub?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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



  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    How would I have a loop wait for a certain amount of time? Just set a for loop so a high number?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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]

  6. #6
    Guest
    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

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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.

  8. #8
    Guest
    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]

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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!

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width