# Restarting a Scene

**URL:** <https://phaser.discourse.group/t/restarting-a-scene/5495>\
**Category:** Phaser 3\
**Created:** [March 14, 2020, 5:35am UTC](https://phaser.discourse.group/t/restarting-a-scene/5495 "2020-03-14T05:35:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamvalecia](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/iamvalecia/32/2957_2.png) [@iamvalecia](https://phaser.discourse.group/u/iamvalecia)\
**Post date:** [March 14, 2020, 5:35am UTC](https://phaser.discourse.group/t/restarting-a-scene/5495/1 "2020-03-14T05:35:38Z")

</div>

This is my first Phaser game.

[Save-a-Dino](https://github.com/iamvalecia/save-a-dino)

I have two things left that I want to do

1. Undo the fade out and Restart the game
2. Credit the people/organizations for the assets and myself on the canvas. I want to give players the option of viewing the credits or restarting the game.

I’m here with help for #1. The “dino” / character returns back to the starting point and so does the “food”/its target. But the obstacles don’t perform, the score doesn’t reset or truncate, and the bg doesn’t return. (I can get rid of the text by `.destroy()`.

I’ve also noticed after the commit that lines 210 and 212, separately and together, cause the scene not to `fadeout` defeating the purpose of `resetFX()` or a `.fadeIn`.

Any other constructive criticism is welcome. I can answer any questions about my code.

---

<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:** [March 14, 2020, 7:13pm UTC](https://phaser.discourse.group/t/restarting-a-scene/5495/2 "2020-03-14T19:13:17Z")

</div>

This is a good game. 😄

There were 2 problems:

- After win/lose, `isGameOver` was flipping back and forth, and the “game over” texts were getting created over and over.
- After restart, the variables `foodCollected` and `lifeYears` weren’t reset, so the new game would go straight to game over again.

I made a PR, you could merge or just look at the changes.

---

<div class="post-metadata">

**Author:** ![iamvalecia](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/iamvalecia/32/2957_2.png) [@iamvalecia](https://phaser.discourse.group/u/iamvalecia)\
**Post date:** [March 15, 2020, 8:25pm UTC](https://phaser.discourse.group/t/restarting-a-scene/5495/3 "2020-03-15T20:25:15Z")

</div>

Thanks. Of course, I merged. It’s my first real merge!

In my last commit on line 176, why did I have so many parentheses???  
`if ((!(right)) && (!(left))) {`  
We’re saying the same thing. Yours looks clearer.

On a serious note, I notice you don’t fade back in. Does the `.restart()` take care of that? What all can `.restart()` do if executed properly?

Are the asteroids showing up on the GitHub page for you? They aren’t for me, just black boxes.

---

<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:** [March 16, 2020, 3:46pm UTC](https://phaser.discourse.group/t/restarting-a-scene/5495/4 "2020-03-16T15:46:18Z")

</div>

When you restart a scene its cameras are discarded and then recreated.

You can fade in again by passing data in `restart()` and then handling it yourself when starting the scene (either in `init()` or `create()`:

https://codepen.io/samme/embed/preview/qBdpeVP?height=300&slug-hash=qBdpeVP&default-tabs=js,result&host=https://codepen.io
