Jump to content

Can't replay a game


Recommended Posts

HI everyone, am working on a school's project and decided to create a shoot'em up.

The big part of the game is working but i have a problem for replay to the game, when the game is over the user can leave or replay, 

 replayButton = this.add.button(700, 650, 'replayButton', function() {
            var self = this;
            this.postScore().then(function() { // Just sending the score on a php server

        }, this, 1, 0, 2);

When i push the button the game start correctly but when i want fire the game crash for this reason : Uncaught TypeError: Cannot read property 'time' of null

i don't know why this.game is null in this function and not in others

Weapon.SingleBullet.prototype.fire = function (source) {
    if (this.game.time.time < this.nextFire) { return; }

    var x = source.x + 115;
    var y = source.y + 80;

    this.getFirstExists(false).fire(x, y, 0, this.bulletSpeed, 0, 0);

    this.nextFire = this.game.time.time + this.fireRate;

    return true;

You can find the JavaScript folder of my project , and excuse me for my english but like a majority of french student am bad ! 


Link to comment
Share on other sites

Are you working with states? If so, remember, if you switch states back and forth, the state do not get recreated, they keep all the values they had before.

The create method gets fired, but the state object is still the same instance as the last time you accessed that state in the game.

So check if you have to reinitialise some of the values on create.

Link to comment
Share on other sites

Thanks for your help, it's working my mistakes was in the state Game,  I declared the array of weapon not at the good place.

I was doing this:

GameStates.Game = function (game) {
    this.currentWeapon = 0;
    this.weapons = [];

And now I declare it in a function in 

GameStates.Game.prototype = {


Link to comment
Share on other sites


  • Recently Browsing   0 members

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