Get moving with timers
Let's take one further step, and, instead of having a static scene, let's add an animation. It is a normal thing for the sun to ascend in the morning. In order to achieve the effect of sunrise every time the form is repainted, we will change the y coordinate that is used for painting the sun's circle and rays. Let's add to our TFormSun
class a private member FSunPosY: double
, which will store the current vertical sun position.
The simplest way to change our scene over time is with the TTimer
component. Drop TTimer
on the form. It has only one event, OnTimer
. The frequency of these events 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 1,000
, which means that the timer fires its event every second. For a smooth animation, this is too much. Change the Interval
property to 20
and double-click on the OnTimer
event. Here, we want to constantly increment the...