In such cases, the Draw/Update
cycle is usually organized. I will give an example:
// Π² Π½Π°ΡΠ°Π»Π΅ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΏΡΠΈ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ: lastUpdateTime = GetCurrentTime(); // ... // ΠΊΠΎΠ΄ ΡΠ΅Π³ΡΠ»ΡΡΠ½ΠΎ Π²ΡΠ·ΡΠ²Π°Π΅ΠΌΠΎΠ³ΠΎ ΠΌΠ΅ΡΠΎΠ΄Π° // (Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, ΡΠΈΠΊΠ» ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠΈ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠΉ) void DoWork() { now = GetCurrentTime(); while (lastUpdateTime + updateStep <= now) { Update(); lastUpdateTime += updateStep; } Draw(); }
where updateStep
is the time allotted for the logic update step; usually equal to 1000 / FramePerSecond
, if measured in milliseconds.
In the Update()
method, we update the state (in this case, the motion tween), and in the Draw()
method, we draw the scene.
To organize a similar method, I think, is not difficult.