1

I am using the game_loop pub package to handle my eventloop. The problem is that it updates way too often. I don't need to update or redraw that often, and input key repetition is also too fast. I do not know much about eventloops or browser redraws, so I might think of it the wrong way, but is there a way to slow the loop down?

Mathias Bak
  • 4,687
  • 4
  • 32
  • 42

2 Answers2

1

Run heavy tasks in the separate Isolate while keeping game loop as lightweight as possible. The game loop should be implemented with window.animationFrame. How do I drive an animation loop at 60fps with Dart? You should learn all about requestAnimationFrame - it's the key to the smooth animations.

And your game logic speed should not depend on the browser FPS(Frames Per Second) use scheduler instead Does Dart have a scheduler?

Community
  • 1
  • 1
JAre
  • 4,666
  • 3
  • 27
  • 45
0

Try adding a timer and avoid adding an onUpdate or onRender handler to your GameLoop instance:

//timer fires 20 times per second, as an example
gameLoop.addTimer(render,0.05,periodic: true);

...
...
render(GameLoopTimer timer)
{
    //draw or update code here
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
NullPumpkinException
  • 1,396
  • 1
  • 18
  • 22