Results 1 to 6 of 6

Thread: moving ball

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Waterloo Canada
    Posts
    2

    Post

    Hi vb experts,

    I'm trying to draw a moving ball in VB. I use bitblt and a for loop to change its position. The problem I have is that the ball is moving too fast (too fast that I couldn't even see it). So, I want some delay in between each bitblt call.

    I couldn't use the "now" function since the smallest interval for "now" is 1 second.

    So, I turn to using a timer. However, a time doesn't accept parameters, so I have difficulties passing the x,y coordinate to it.

    Then, I thought of using a global flag variable, say DoDraw.
    I set DoDraw = True inside the timer, and using something like the following in my drawing rountine.

    for i = 0 to 100

    while DoDraw = false
    DoEvents
    wend
    DoDraw = false

    bitblt ....

    next i

    However, I don't understand why eventhough I have set the interval of the timer to be 1, this piece of code still run very very slowly. Or should I say the ball moves very slow.
    (a lot slower than 1 millisec in between.)

    Can anyone show me a clever way of delaying less than a second?

    Thank you so much
    Happy programming

    Bugson

  2. #2
    New Member
    Join Date
    Jan 2000
    Location
    mount clemens, mi, us
    Posts
    12

    Post

    well.. the timer would be the best way.
    and you could do it with a little modification.
    but there is a way i think would work for you in the for-next loop.

    make it for i=0 to 100 step x

    the step tells it to do it in increments of x. so make x a decimal number (say, .5) and it should slow it down some.

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    Hi,

    Please don't take a timer. PLEASE! I hate timers! Take GetTickCount from the API and make your own timer...

    Put this anywhere in your loop:

    Code:
    Dim Temp As Long
    Dim Delay as Long
    
    Temp = GetTickCount
    Delay = 10 'Ten milliseconds
    
    While Temp + Delay > GetTickCount
       DoEvents 'Optionally
    Wend

    (Thats a loop which waits for <Delay> milliseconds before it continues. It's the same like a timer, but IMO much better

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Waterloo Canada
    Posts
    2

    Post

    Thanks guys. I tried gettickcount and it is exactly what I want.

    P.S fox, I hate timer too.

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088


    Doesn't anyone hear what I'm saying? *g*

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827

    Hi Fox

    I hear ya Fox Loud and clear.

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