AchimS Posted July 28, 2017 Share Posted July 28, 2017 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? Quote Link to comment Share on other sites More sharing options...
lloydevans Posted July 28, 2017 Share Posted July 28, 2017 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 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 28, 2017 Share Posted July 28, 2017 1) there's "stage.removeChildren()" 2) You forgot to call the function. just ".click" does not invoke it, you need "()". Its not a pascal/C# Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.