Jump to content

Game speeds up after reloading


AchimS
 Share

Recommended Posts

Hello everyone!

I just recently got into PIXI.js and started with a tutorial from kittykatattack on GitHub which can be found here: https://github.com/kittykatattack/learningPixi#introduction

I finished the tutorial and everything works great! After that I wanted to expand the game and add a "Try again" or "Play again" button to the end scene and I got that to work aswell. But each time the game restarts it gets quicker and quicker. It seems like the speed is doubling on each restart. 

I added this code to the end state function:

tryAgainMessage.click;
playAgainMessage.click;

    tryAgainMessage.click = function (e) {
        for (var i = stage.children.length - 1; i >= 0; i--) { stage.removeChild(stage.children[i]);};        
        gameScene.visible = true;
        gameOverScene.visible = false;
        state = setup;
    }
    playAgainMessage.click = function (e) {
        for (var i = stage.children.length - 1; i >= 0; i--) {	stage.removeChild(stage.children[i]);};        
        gameScene.visible = true;
        gameOverScene.visible = false;
        state = setup;
    }

Does anyone know how I can properly restart the game once the message is clicked?

Link to comment
Share on other sites

Without looking at any code, it sounds like you are doubling up some movement logic in the game loop by adding callbacks in the setup function(s), but not removing existing ones. You might want to look at creating some kind of "reset" state/function, which resets the things you want, but doesn't call some of the unneeded initial setup logic again.

I expect someone might be able to give you a more detailed answer than this with specific reference to the code, but I don't have time to look through it :P

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...