Restarting a Scene

This is my first Phaser game.

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.

1 Like

This is a good game. :smile:

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.

1 Like

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.

2 Likes

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():