Is Flame based on CPU for update loop?

Viewed 126

I'm creating a little game and I've test it on different phones with different CPU (Samsung G31F and G935F). I've seen that my charactere walked faster on a recent phone and slower on an old phone, so that's my question:

Is Flame based on CPU frequency when Update() function is called ? And how often is called Update() in one second ?

Thanks

1 Answers

In your update function you get back the delta time (dt), which is the time passed since the last update tick was run, this variable you should use to make your component move in the same speed on all devices.

So this following example will make your Character component move with 100 pixels per second in X-axis.

class Character extends PositionComponent {
  const speed = 100; // Pixels per second
  ...
  @override
  void update(double dt) {
    super.update(dt);
    x += speed * dt;
  }
}

If you use for example the effects api on your component you will not have to care about the delta time.

Related