Get moving with timers
Let’s go a step further – instead of having a static scene, we’ll add some animation. It is a normal thing for the Sun to ascend in the morning. To achieve the effect of sunrise, the form must be repainted. We are going to change the Y
coordinate that is used for painting the Sun’s circle and rays. To do this, we’ll add a private member called FSunPosY: double
to our TFormSun
class that will store the current vertical position of the Sun.
The simplest way to change our scene over time is with the TTimer
component. To do so, drop a timer on the form. It has only one event, OnTimer
. The frequency of this event is controlled by the Interval
property, which specifies the number of milliseconds between firing the OnTimer
event. The default value of the Interval
property is 1000
, which means that the timer fires its event every second. For a smooth animation, this is too slow. Change the Interval
property to 20
and double-click...