doevents problem.

copiloto

Member
Licensed User
Longtime User
Hello,

I'm trying to move a ball in the screen.

A piece of my code:

For a=1 To 500 step 1
' doevents?
canvas.DrawCircle(a-1,100,10,Colors.Black,True,1)
canvas.DrawCircle(a,100,10,Colors.White,True,1)
activity.Invalidate
Next

The thing is that if 'doevents' is not introduced into the For/next cycles, the circle is only visible at the end of the loop, when a=500. It takes only 1 second!
Otherwise, if 'doevents' is introduced, the process gets too slow, I mean, the circle is able to be watched from 1 to 500, but it takes much more time to cross the screen... around 15 seconds?..
I know that a posible solution is to increase the step, but would like if it's possible to accelerate/optimize this code. Is doevent neccesary? and what about activity.Invalidate?

Thanks a lot and happy new year!!:sign0060:
 

klaus

Expert
Licensed User
Longtime User
Upvote 0

copiloto

Member
Licensed User
Longtime User
Hi Klaus,

Thanks very much for your aswer. Now:

Sub timer_Tick
''' (timer.Interval=30 )
rect1.Top=20
rect1.Left=a-11
rect1.Right=a+10
rect1.Bottom=40
esfera.DrawCircle(a-1,30,10,Colors.Black,True,1)
esfera.DrawCircle(a,30,10,Colors.White,True,1)
activity.Invalidate2(rect1)
a=a+1
End Sub

Yet, although really is going faster using invalidate2, I expected a better performance. It seems that graph apps run much more faster in the background. Do you think it would be better using drawbitmap than drawcircle in order to gain performance?

Thanks very much again.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I made some tests, drawing a bitmap is not faster than drawing the circle (in the tests I made).
To make it faster you should set the timer interval to a lower value than 30.
I made tests with even 1 millisecond, works not too bad, but this timer interval is somewhat short for the emulator.
With a bitmap you have more freedom in the design.

Attached my small test program.

Best regards.
 

Attachments

  • BallMove.zip
    6.5 KB · Views: 227
Upvote 0

copiloto

Member
Licensed User
Longtime User
Thanks very much, klaus.

Unfortunately still haven't test your examples cos had to travel away yesterday.
Yet, i'll buy a cheap mobile (Have thought in htc wildfire...), for knowing real behaviour.

cheers 'n happy new year!
 
Upvote 0

copiloto

Member
Licensed User
Longtime User
Klaus,

I have installed your program. Yes, it seems that there's no difference about performance.

In a friend android telephone, it takes (in both cases) 20 seconds to cross the screen in horizontal view (speed=1). Do you remember how many time it takes on your phone?
Otherwise, in different apps, speed is bigger than WMobile, even charging graphs in background.

Thanks a lot.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Do you remember how many time it takes on your phone?
I tested it only on the Emulator, the speed wasn't all time constant.

Otherwise, in different apps, speed is bigger than WMobile, even charging graphs in background.
I noticed also a bigger speed in graphics even in the Emulator.

Best regards.
 
Upvote 0
Top