PDA

Click to See Complete Forum and Search --> : moving ball


bugson
Mar 7th, 2000, 11:52 AM
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

ljdarten
Mar 7th, 2000, 07:25 PM
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.

Fox
Mar 7th, 2000, 09:02 PM
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:


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 ;)

bugson
Mar 8th, 2000, 02:47 AM
Thanks guys. I tried gettickcount and it is exactly what I want.

P.S fox, I hate timer too.

Fox
Apr 2nd, 2000, 10:54 AM
:(

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

HarryW
Apr 2nd, 2000, 10:46 PM
I hear ya Fox :) Loud and clear.