Is there fixedupdate like Unity in Phaser?

I am making a new game using phaser 3 but I am new at phaser.
In scene there is update() method.
This is called in real time but calling speed is different accoding to the device.
Especially it is slow on mobile.
So I want to call it every 10 seconds.
Are there any ways to do like this?

Do you mean like setting its FPS?

update() {
this.m_droper.moveDroper();
}

public moveDroper() : void {
if(this.x > 350) {
this.nDroperMoveFlag = 0;
} else if(this.x < 70) {
this.nDroperMoveFlag = 1;
}

    if(this.nDroperMoveFlag == 1) {
        this.x = this.x + 2;
    } else {
        this.x = this.x - 2; 
    }              
}

This is update method in mainscene. Using droper(sprite) is moving.
But the moving speed is not same on all devices. I think this is because the update method calling speed is different according to the device. I am not sure if this is clear for you.

Hi,
The update loop is sync with the screen refresh rate, but you can add parameters to update:

update(time, delta)

Could you possibly let me know where can I see this example?


update(time, delta) {
  this.m_droper.moveDroper(delta);
}

public moveDroper() : void {
  if(this.x > 350) {
    this.nDroperMoveFlag = 0;
  } else if(this.x < 70) {
    this.nDroperMoveFlag = 1;
  }

  if(this.nDroperMoveFlag == 1) {
    this.x += 0.02 * delta;
  } else {
    this.x -= 0.0 2 * delta;
  }              
}

But if you want to check collisions further in the game, you need to use velocity on your sprites, velocity already take care of delta.

2 Likes

Thanks so much. I will see this examples.
Can we have a talk via skype?

No skype here, and i don’t speak english sorry

OK. So this will cause same effects for all devices such as desktop and mobile devices?

Not 100% sure so test it before, if all your device have a 60Hz screen, logically yes

If you are tagetting different devices and want to lower the fps of those I would recommend setting the fps in the config.

fps: {
target: 30,
forceSetTimeOut: true
}

Thanks for your reply.
Do you know how to solve the memory leak problem?
After I destroy sprite, console still shows it.
Do you have any idea?

Make sure you don’t have any variables referencing the sprite, or functions created in a scope that has access to any said variables. A good way of ensuring that is to set all references you have to the sprite to null.