timer too slow... why?

D

Diego_Atos

I've create a "stupid" animation. A simple label that bounce on borders
of my form. Motion is ruled by a timer that set the timing of every
steps.

If I set the interval at "1000" it works properly, howevery if i set it
at "10" or less, it warks slower than it would be.

Anyone can help me?


Excuse my bad english


Thanks
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 
M

Morten Wennevik

Hi Diego,

The timer event is not guaranteed to execute. If your program is busy the timer event might not get time to execute before another timer event is sent. The first waiting event is then cancelled. In effect setting timer to 10 might not seem any faster than setting it to 100.

Dropped timer event is affected by your processor speed, how busy your program is, and how long it takes to execute the timer event code.
 
D

Diego_Atos

Risposta a:
Richard Blewett ([email protected])
_________________
System.Timers.Timer

this
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 
D

Diego_Atos

Risposta a:
Morten Wennevik ([email protected])
_________________
Hi Diego,

The timer event is not guaranteed to execute. If your program is busy the timer event might not get time to execute before another timer event is sent. The first waiting event is then cancelled. In effect setting timer to 10 might not seem any faster than setting it to 100.

Dropped timer event is affected by your processor speed, how busy your program is, and how long it takes to execute the timer event code.

i know this, but how can i really set the speed of my motion?
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 
M

Morten Wennevik

Risposta a:
Morten Wennevik ([email protected])
_________________

i know this, but how can i really set the speed of my motion?

Maybe do the animation in a separate thread, or animate according to time span between last "frame" and current time.
 
N

Niki Estner

Diego_Atos said:
Risposta a:
Morten Wennevik ([email protected])
_________________

i know this, but how can i really set the speed of my motion?

speed = distance / time

If you can't lower the time, increase the distance.

The human eye isn't capable of recognizing more than about 25 images per
second, so a timer setting of about 40 is well enough.

Move your label by a greater distance per timer tick.

Niki
 
R

Richard Blewett

If you are doing "real" animation then you may be better off using DirectX
(it has a managed wrapper) rather than a timer.

The problem with timer events from a synchronized System.Timers.Timer is
that if the UI thread is busy doing something else (processing another
event) then the timer cannot execute its callback on the UI thread and
eventually, if the UI thread is very busy, you'll end up with a whole slew
of callbacks queued so when teh UI thread becomes free you will get a sudden
rush of activity. In other words the motion of your animation will be very
jerky.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
 
D

Diego_Atos

Risposta a:
Niki Estner ([email protected])
_________________
Move your label by a greater distance per timer tick.

increasing the distance makes a non fluid animation.
the label would jump from a point to another.


Ciao
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 
N

Niki Estner

Diego_Atos said:
Risposta a:
Niki Estner ([email protected])
_________________


increasing the distance makes a non fluid animation.
the label would jump from a point to another.

Did you measure how much time elapses between two ticks?
Do you use that time as a factor in your motion equation?

Niki
 
D

Diego_Atos

Risposta a:
Niki Estner ([email protected])
_________________
Did you measure how much time elapses between two ticks?

yes. if i set it at, for exemple, 6000, elapsed time is correct (6 secs)
less than 100 it doesn't work properly. It's a process priority problem,
that a cannot solve.
Do you use that time as a factor in your motion equation?

yes. Every tick, i increase the coordinates

--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 
N

Niki Estner

Diego_Atos said:
Risposta a:
Niki Estner ([email protected])
_________________


yes. if i set it at, for exemple, 6000, elapsed time is correct (6 secs)
less than 100 it doesn't work properly. It's a process priority problem,
that a cannot solve.

That's a misunderstanding about how it's supposed to work. The elapsed time
you specify is the *minimum* time.
yes. Every tick, i increase the coordinates

That is, do you have a formula like this (pseudocode):

Position += speed * (CurrentTime - OldTime);
OldTime = CurrentTime;

Also, if I got you, you're moving a Windows.Forms - Label control? Do you
ensure it gets redrawn immediately? Changing the position does not
neccessarily redraw it that instant.

Usually 50-100 ms is enough for a fluid animation, however if you find you
really need higher frame rates, consider running a loop instead of using
timers at all; This will burn CPU power, but it'll be as fast as it gets.

Niki
 
G

George Neuner

I've create a "stupid" animation. A simple label that bounce on borders
of my form. Motion is ruled by a timer that set the timing of every
steps.

If I set the interval at "1000" it works properly, howevery if i set it
at "10" or less, it warks slower than it would be.

The timer is accurate only to 1/18 of a second (about 55 ms) - trying
to set it lower is useless. This limitation is specified in the docs
for the timer class. Non managed timers have the same limitation -
they are all run from the system heartbeat clock.

For fine animation you have to use multimedia timers or, as some
others have suggested, a separate thread.

George
 
D

Diego_Atos

Risposta a:
George Neuner (gneuner2/@comcast.net)
_________________
For fine animation you have to use multimedia timers or, as some
others have suggested, a separate thread.

thanks
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top