Call update method with setInterval present

There are objects in my game engine that need to be updated periodically. For example, a scene can lower its alpha, so I set the interval that it does. In addition, the camera sometimes needs to twist a little, which requires interpolation by the rotation property.

I see that there are two ways to solve these problems:

  • Have an update () method that calls all other object update methods. Objects track the time since the last update and act accordingly.

  • Make setIntervaleach update method of the object.

What is the best solution and why?

+5
source share
4 answers

setInterval , . , , . , 10 , 100 , , , , 200 . ( ).

( ), , . , 2 .

setInterval , setInterval ?

+4

, , update() , .

update(), , - / , update(), / . (EventListener)

, , / (, ). .

+1

update() setInterval.

, , .

, , , , ..

0

. setInteval , , setTimeout.

, , ( ). , . , , , , , .

setTimeout , , . , . setInterval , .

, setInteval , . .

0
source

All Articles