Jump to content

Game Over Screen - Destroy complete state


ITpaolo
 Share

Recommended Posts

Hi Community,

I want to make an Game Over screen for my Top Down Test Game.

My Code is in states.

I did load the state with

"game.state.add('gameover'), gameoverState);"

on my play.js 

gameover: function () {

        if (sprite.body.y > 700) {
            game.state.start('gameover');
        }

gameover.js

var gameoverState = {
    create: function () {

        var gameoverLabel = stateText = game.add.text(game.world.centerX, game.world.centerY, ' ', {font: '84px Arial', fill: '#F2F2F2'});
        stateText.anchor.setTo(1.1, 0.2);

    },

    update: function () {

        game.world.removeAll();
        stateText.text = " GAME OVER \n Click to restart";
        stateText.visible = true;

        //the "click to restart" handler
        game.input.onTap.addOnce(function () {
        game.state.restart();}, this.start);
    },

    start: function () {
        game.state.start('menu');
    }
};

Everytime I die this will pop up, no text just all the obj and layer resize in 16x16 or 32x32.

 

Regards,

ITpaolo

 

btw. Sorry, i'm nooby in Phaser. :-P

 

Unbenannt.PNG

 

 

EDIT:

 

I know now that this was the problem for it:

play.js

/*
        if (sprite.body.x < -30) {
            sprite.body.x = this.game._width - 30;
        }
        if (sprite.body.x > 650) {
            sprite.body.x = this.game._width - 650;
        }
        if (sprite.body.y < -50) {
            sprite.body.y = this.game._height - 50;
        }
        if (sprite.body.y > 660) {
            sprite.body.y = this.game._height - 650;
        }
*/

But now Idk how to do the Game Over screen, any help?

 

EDIT2: Did now:

play.js

if (sprite.body.y > 650) {
            stateText.text = " GAME OVER \n Click to restart";
            stateText.visible = true;

            //the "click to restart" handler
            game.input.onTap.addOnce(function () {
            game.state.restart(this.start);});
        }
    },
    start: function () {
        game.state.start('menu');
    }

Its now restarting the 'play.js', if I click "restart" but I want that he start the "menu.js" state, any help 2.0? ^^

 

EDIT3: I fixed it, hope I can help anyone.

play.js

if (sprite.body.y > 650) {
            stateText.text = " GAME OVER \n Click to restart";
            stateText.visible = true;

            //the "click to restart" handler
            game.input.onTap.addOnce(function () {
            game.state.start('menu');});
        }
    },
    start: function () {
        game.state.start('menu');
    }

 

 

EDIT4: The last edit, now I fixed it really, he now start the 'gameover.js' when the sprite die.^^

play.js

if (sprite.body.y > 650) {
            game.state.start('gameover');
        }

gameover.js

var gameoverState = {
    create: function () {

        var gameoverLabel = stateText = game.add.text(500, 300, ' ', {font: '50px Arial', fill: '#F2F2F2'});
        stateText.anchor.setTo(1.1, 0.2);

    },

    update: function () {
        if (sprite.body.y > 650) {
            stateText.text = " GAME OVER \n Click to restart";
            stateText.visible = true;

            //the "click to restart" handler
            game.input.onTap.addOnce(function () {
            game.state.start('menu');});
        }
    }
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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