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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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