Jump to content

Game won't restart after completed state


Julia
 Share

Recommended Posts

Hey,

 

I've added a 'complete' state to my game.

Here is a playable example: juliahofs.nl/platformer3/platformer_test.html

 

You have to pick up all 10 coins to be able to see the problem. When you see the text, just click on the screen and continue.

I've put this piece of code in it: 

Platformer.Complete = function (game) {};Platformer.Complete.prototype = {create: function () {var wonImage = game.add.sprite(game.world.centerX, 200, 'IWon');wonImage.anchor.setTo(0.5, 0.5);var restartText = game.add.text(game.world.centerX, 500, "START", {font: "35px Roboto", fill: "#000", align: "center"});restartText.anchor.setTo(0.5, 0.5);restartText.inputEnabled = true;restartText.events.onInputDown.add(function() {game.state.start('Play');}, this);}};

When I click the start text, the game only flickers. It doesn't restart the game. I'm guessing it has something to do with the onInputDown event? Or should I destroy the image and the text of the complete state (I thought this was done automatically when changing states).

Any tips? :)

Link to comment
Share on other sites

Thanks for you answer, Mariusz. That seems to make sense. But how would I return the score back to zero? I tried this:
 

create: function(){        score = 0;    score = game.add.text(20 , 20, "0 / 10", fontStyle);    score.fixedToCamera = true;},updateText: function() {    score.setText(count + " / 10");},
But still the same problem... Or did you mean the 'count' variable?
Link to comment
Share on other sites

Ah yes, that was indeed the problem :) Now I have this: 

create: function () {        count = 0;    score = game.add.text(20 , 20, "0 / 10", fontStyle);    score.fixedToCamera = true;},updateText: function() {    score.setText(count + " / 10");},

Thanks a lot!!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...