notalentgeek Posted December 15, 2014 Share Posted December 15, 2014 I have problem when changing between state, the console always returns this error:Phaser.StateManager - No state found with the key: StateMainI have checked that all of my codes work fine, except the error happened when executing this line of code:this.game.state.start('StateMain');Can someone point to which error I made? Here are all my code.index.html<!DOCTYPE HTML><html><head> <meta charset = "UTF-8" /> <title>Phaser State Test</title> <script src = "phaser-2.2.1/build/phaser.js"></script> <script src = "StateMain.js"></script> <script src = "StateOpening.js"></script></head><body> <script type = "text/javascript"> var game = new Phaser.Game(320, 240, Phaser.AUTO); //States loads. game.state.add('StateOpening', StateTest.StateOpening); game.state.add('StateMain', StateTest.StateMain); //Start the initial state. game.state.start('StateOpening'); </script></body></html>StateOpening.jsStateTest = {};StateTest.StateOpening = function(game){ var logo = null; var logoAnimDefault = null;};StateTest.StateOpening.prototype = { preload: function(){ this.load.spritesheet('NotalentLogo', 'assets/notalentlogo.png', 128, 32); }, create: function(){ logo = game.add.sprite(this.game.world.width/2, this.game.world.height/2, 'NotalentLogo'); logo.anchor.setTo(0.5, 0.5); logoAnimDefault = logo.animations.add('Default', [0, 2], 2, false); logoAnimDefault.play(2, false); logoAnimDefault.onComplete.add(this.LogoOnComplete, this); }, LogoOnComplete: function(sprite, animation){ this.game.state.start('StateMain'); }};StateMain.jsStateTest = {};StateTest.StateMain = function(game){};StateTest.StateMain.prototype = { update: function(){ console.log("TEST"); }}; Link to comment Share on other sites More sharing options...
rich Posted December 15, 2014 Share Posted December 15, 2014 You're erasing the StateTest object in StateOpening.js - it's already defined at the start of StateMain, it shouldn't be defined ever again beyond this point, just added to. Link to comment Share on other sites More sharing options...
notalentgeek Posted December 15, 2014 Author Share Posted December 15, 2014 You're erasing the StateTest object in StateOpening.js - it's already defined at the start of StateMain, it shouldn't be defined ever again beyond this point, just added to.It works! Thank you so much . I just remove the first line in the StateMain.js and everything works fine! Link to comment Share on other sites More sharing options...
Recommended Posts