Jump to content

GameState torture


Rohmke
 Share

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);
  
  game.state.start('Boot');
};

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

processPlayerInput:function(){
    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) {
          this.state.start('Game2');
        }else{
          this.fire();
        }
      };

and it give the error.

Here is the start of Game2:

BasicGame.Game2 = function (game) {

};

BasicGame.Game2.prototype = {

  create: function () {
    this.setbak();
    this.setplayer();
    this.setenemies();


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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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