Jump to content

GameState torture


Recommended Posts

Hello, new to this forum so sorry in advance if I break any etiquette norms.

Here's the deal: I've been getting the "Phaser.StateManager - No state found with the key: Game2" error each time I switch from Game to Game2 state, I've spent the last 3 days reading tutorials, guides and forums of people with similar issues but found no solution yet, all states work except Game2, which is an exact copy of Game, but with different name (Game2).

This are the files in html:

  <script src="phaser.js"></script>
  <script src="game2.js"></script>
  <script src="boot.js"></script>
  <script src="preloader.js"></script>
  <script src="mainMenu.js"></script>
  <script src="app.js"></script>
  <script src="game.js"></script>

This is the content of app which creates the game and contains all states:

window.onload = function() {
  var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer');

  game.state.add('Boot', BasicGame.Boot);
  game.state.add('Preloader', BasicGame.Preloader);
  game.state.add('MainMenu', BasicGame.MainMenu);
  game.state.add('Game', BasicGame.Game);
  game.state.add('Game2', BasicGame.Game2);

Boot calls Preloader, which calls MainMenu, which calls Game, up to this point it works perfectly, but then in Game I do this:

    this.player.body.velocity.x = 0;
    this.player.body.velocity.y = 0;
    if (this.input.activePointer.isDown && this.physics.arcade.distanceToPointer(this.player) > 15) {
        this.physics.arcade.moveToPointer(this.player, this.player.speed);
    if (this.input.keyboard.isDown(Phaser.Keyboard.Z) || this.input.activePointer.isDown) {
        if (this.returnText && this.returnText.exists) {

and it give the error.

Here is the start of Game2:

BasicGame.Game2 = function (game) {


BasicGame.Game2.prototype = {

  create: function () {

and the rest of the state...

I am going nuts, plz help

Edited by Rohmke
Link to comment
Share on other sites

Do you see the Game2 state when you call this.state.states?

Are you calling remove/destroy on any state objects somewhere?

Does calling this.state.checkState("Game2") before starting that state return false?

Have you tried loading the game2.js file at the bottom of the HTML file?

Kindof obvious questions that will likely be false, but it could also be something obvious being missed that's causing the problem.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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