# Is there fixedupdate like Unity in Phaser?

**URL:** <https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953>\
**Category:** Phaser 3\
**Created:** [April 18, 2020, 9:03am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953 "2020-04-18T09:03:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 9:03am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/1 "2020-04-18T09:03:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ReydVires](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/reydvires/32/939_2.png) [@ReydVires](https://phaser.discourse.group/u/ReydVires)\
**Post date:** [April 18, 2020, 10:19am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/2 "2020-04-18T10:19:06Z")

</div>

> [@Luo](#):
>
> This is called in real time but calling speed is different accoding to the device

Do you mean like setting its FPS?

---

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 10:24am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/3 "2020-04-18T10:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [April 18, 2020, 10:51am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/4 "2020-04-18T10:51:06Z")

</div>

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

```javascript
update(time, delta)

```

---

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 11:16am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/5 "2020-04-18T11:16:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [April 18, 2020, 11:32am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/6 "2020-04-18T11:32:23Z")

</div>

> **[Phaser - Examples - World Time](https://phaser.io/examples/v3/view/timestep/world-time)**
>
> Desktop and Mobile HTML5 game framework. A fast, free and fun open source framework for Canvas and WebGL powered browser games.

  

> **[Phaser - Examples - Delta History](https://phaser.io/examples/v3/view/timestep/delta-history)**
>
> Desktop and Mobile HTML5 game framework. A fast, free and fun open source framework for Canvas and WebGL powered browser games.

```javascript
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.

> **[Phaser - Examples - Basic Platform](https://phaser.io/examples/v3/view/physics/arcade/basic-platform)**
>
> Desktop and Mobile HTML5 game framework. A fast, free and fun open source framework for Canvas and WebGL powered browser games.

---

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 11:34am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/7 "2020-04-18T11:34:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [April 18, 2020, 11:36am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/8 "2020-04-18T11:36:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 11:37am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/9 "2020-04-18T11:37:21Z")

</div>

> [@BlunT76](#):
>
> 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; } }

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

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [April 18, 2020, 11:39am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/10 "2020-04-18T11:39:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Phailser](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/phailser/32/3187_2.png) [@Phailser](https://phaser.discourse.group/u/Phailser)\
**Post date:** [April 18, 2020, 11:46am UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/11 "2020-04-18T11:46:09Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![Luo](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Luo](https://phaser.discourse.group/u/Luo)\
**Post date:** [April 18, 2020, 1:03pm UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/12 "2020-04-18T13:03:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![embeddedt](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/embeddedt/32/3179_2.png) [@embeddedt](https://phaser.discourse.group/u/embeddedt)\
**Post date:** [April 18, 2020, 10:44pm UTC](https://phaser.discourse.group/t/is-there-fixedupdate-like-unity-in-phaser/5953/13 "2020-04-18T22:44:14Z")

</div>

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`.
