# Pausing and delaying a resumed scene

**URL:** <https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781>\
**Category:** Phaser 3\
**Created:** [June 15, 2021, 1:35pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781 "2021-06-15T13:35:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shutt90](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/shutt90/32/5286_2.png) [@Shutt90](https://phaser.discourse.group/u/Shutt90)\
**Post date:** [June 15, 2021, 1:35pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/1 "2021-06-15T13:35:35Z")

</div>

Trying to work out how to set a timer off when the ball goes out of bounds in a pong game, at the moment its automatically relaunching instantly. Been going with a scene pause and resume with set interval a few different ways.  
Always starting with…  
if (this.ball.body.x \< this.playerPaddle.body.x - 25) {  
enemyCurrentScore++;  
this.scene.restart();  
this.scene.pause();

```javascript
        setInterval(function () {
          this.scene.resume;
        }, 3000);

```

And

```javascript
        this.time.delayedCall(
          3000,
          function () {
            return this.scene.resume;
          },
          [],
          this
        )

```

also I have

```javascript
    this.resumeGame = function () {
      this.pauseText = this.add.text(250, 200, "NEW GAME", {
        fontSize: "64px",
        fill: "#fff",
      });

```

Which is the function inside the other.  
Would appreciate any help, been on this for hours 😃

---

<div class="post-metadata">

**Author:** ![Mastertaco](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/mastertaco/32/5290_2.png) [@Mastertaco](https://phaser.discourse.group/u/Mastertaco)\
**Post date:** [June 15, 2021, 3:02pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/2 "2021-06-15T15:02:10Z")

</div>

Try using setTimeOut instead:

```javascript
setTimeOut(()=>{ //(function, time)
           this.scene.resume;
},3000);

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 15, 2021, 3:56pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/3 "2021-06-15T15:56:51Z")

</div>

👋

You must write callbacks as

```javascript
setTimeout(() => {
  this.scene.restart();
}, 3000);

```

Likewise

```javascript
this.time.delayedCall(3000, this.scene.restart, [], this.scene);

```

or

```javascript
this.time.delayedCall(
  3000,
  function () {
    this.scene.restart();
  },
  [],
  this
);

```

It looks like you want to do pause then restart after delay. This is a little tricky because a paused scene doesn’t advance its clock so timer events (as in `delayedCall()`) will not be called.

You can do a fake pause:

```javascript
gameOver = true;
this.scene.physics.world.pause();
this.time.delayedCall(3000, this.scene.restart, [], this.scene);

```

Or you can use `setTimeout()` (not `setInterval()`, which is a repeating interval):

```javascript
setTimeout(() => {
  this.scene.restart();
}, 3000);

```

---

<div class="post-metadata">

**Author:** ![Shutt90](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/shutt90/32/5286_2.png) [@Shutt90](https://phaser.discourse.group/u/Shutt90)\
**Post date:** [June 16, 2021, 6:16pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/4 "2021-06-16T18:16:19Z")

</div>

Unfortunately I couldn’t get this to work. After the setTimeout(this.scene.restart, 3000) I get an error after the 3seconds saying:

Uncaught TypeError: Cannot read property ‘queueOp’ of undefined  
at restart (phaser.js?d4ef:198993)

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 16, 2021, 6:58pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/5 "2021-06-16T18:58:41Z")

</div>

I wasn’t passing context correctly. ☹ I corrected the post above.

---

<div class="post-metadata">

**Author:** ![Shutt90](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/shutt90/32/5286_2.png) [@Shutt90](https://phaser.discourse.group/u/Shutt90)\
**Post date:** [June 16, 2021, 7:03pm UTC](https://phaser.discourse.group/t/pausing-and-delaying-a-resumed-scene/9781/6 "2021-06-16T19:03:55Z")

</div>

Thank you so much, headache over 😃
