Book Code Correction

In my recent book on Creating and Publishing HTML5 games in 24 hours has a few mistakes. The mistakes were not there during publishing but due some changes in Phaser they now exists. Fortunately they are easy to fix. In the scoreBox class add the following code:

destroyMe()
    {
        emitter.off(G.SCORE_UPDATED, this.scoreUpdated, this);
    }

And in SceneMain.js change the playAgain function to this:

playAgain() {
        this.scoreBox.destroyMe();
        this.scoreBox.destroy();
        this.scene.start("SceneOver");
    }

This will turn off the listener for the scoreBox just before destroying it. The game was adding a listener every time play again was invoked.

Leave a Reply