beuleal Posted February 16, 2015 Share Posted February 16, 2015 Hi guys, im creating a new project using:$ yo phaser-officialMy web server is an apache. Im having this problem:Phaser.StateManager - No state found with the key: boot What is wrong? I didnt changed the files, except the index.html, i did: From <script src="js/phaser.js"></script> <script src="js/game.js"></script>to <script src="phaser.js"></script> <script src="game/main.js"></script> Link to comment Share on other sites More sharing options...
Triplanetary Posted February 16, 2015 Share Posted February 16, 2015 Presumably somewhere in your code you're calling for the "boot" state with this: game.state.start('boot'); without having defined a boot state, which would look like this: game.state.add('boot', myGame.boot); and should come before the first attempt to start the boot state. Note that "myGame.boot" refers to a function, which you'll need to provide yourself, and can be called anything. I just called it "myGame.boot" as an example. This function will contain the code of the boot state. Link to comment Share on other sites More sharing options...
beuleal Posted February 17, 2015 Author Share Posted February 17, 2015 @triplanetary Tks for ur answer, and i already fixed it with this tutorial: http://www.emanueleferonato.com/2014/08/28/phaser-tutorial-understanding-phaser-states/ Link to comment Share on other sites More sharing options...
DuranDuran Posted September 17, 2017 Share Posted September 17, 2017 I have a question regarding this issue. I am getting the same error. Any help would be appreciated. I wanted to use an object to contain the game, so maybe that is the issue. I define the object, RunRun, on the index.html page. I define it within the script tag. Here is what I am using for the index.html page: <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <title>Phaser Basic Project Template</title> <script type="text/javascript" src="js/phaser.js"></script> <script type="text/javascript" src="js/Boot.js"></script> <script type="text/javascript" src="js/Preloader.js"></script> <script type="text/javascript" src="js/MainMenu.js"></script> <script type="text/javascript" src="js/Game.js"></script> </head> <body> <div id="gameContainer"></div> <script type="text/javascript"> window.onload = function() { // Create your Phaser game and inject it into the gameContainer div. // We did it in a window.onload event, but you can do it anywhere (requireJS load, anonymous function, jQuery dom ready, - whatever floats your boat) var RunRun = RunRun || {}; RunRun.game = new Phaser.Game(1024, 768, Phaser.CANVAS, 'gameContainer'); // Add the States your game has. // You don't have to do this in the html, it could be done in your Boot state too, but for simplicity I'll keep it here. RunRun.game.state.add('Boot', RunRun.Boot); RunRun.game.state.add('Preloader', RunRun.Preloader); RunRun.game.state.add('MainMenu', RunRun.MainMenu); RunRun.game.state.add('Game', RunRun.Game); // Now start the Boot state. RunRun.game.state.start('Boot'); }; </script> </body> </html> And here is the Boot.js file: var RunRun = RunRun || {}; RunRun.Boot = function() {}; console.log("hello world!!!!!!!!!"); RunRun.Boot.prototype = { init: function() { // Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1 this.input.maxPointers = 1; // Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here: this.stage.disableVisibilityChange = true; if (this.RunRun.device.desktop) { // If you have any desktop specific settings, they can go in here this.scale.pageAlignHorizontally = true; } else { // Same goes for mobile settings. // In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768" this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.setMinMax(480, 260, 1024, 768); this.scale.forceLandscape = true; this.scale.pageAlignHorizontally = true; } }, preload: function() { // Here we load the assets required for our preloader (in this case a background and a loading bar) this.load.image('preloaderBackground', 'assets/images/testLogo.png'); this.load.image('preloaderBar', 'assets/images/preloadr-bar.png'); }, create: function() { // By this point the preloader assets have loaded to the cache, we've set the game settings // So now let's start the real preloader going this.state.start('Preloader'); } }; Link to comment Share on other sites More sharing options...
samme Posted September 18, 2017 Share Posted September 18, 2017 @DuranDuran what is the exact error message? Link to comment Share on other sites More sharing options...
DuranDuran Posted September 19, 2017 Share Posted September 19, 2017 The error message is -> Phaser.StateManager - No state found with the key: Boot Please note, the index.html file is in the root folder of the project. The Boot.js file is in the js subdirectory. I have been doing some experiments, and if I remove the line var RunRun = RunRun || {}; from the index.html file then everything loads, the Phaser.StateManager finds the Boot key and everything starts to load. Any idea why? Link to comment Share on other sites More sharing options...
samme Posted September 19, 2017 Share Posted September 19, 2017 Use var RunRun = window.RunRun || (window.RunRun = {}); Link to comment Share on other sites More sharing options...
DuranDuran Posted September 20, 2017 Share Posted September 20, 2017 Great, it worked, thanks. I appreciate it. I have one other question, why did it work? Was it because I needed to attach the object RunRun to the window? Was I in the scope of the window object? Link to comment Share on other sites More sharing options...
samme Posted September 20, 2017 Share Posted September 20, 2017 In all the external scripts, var RunRun (outside a function) creates a global variable. In the window.onload function var RunRun creates a new local variable hiding the global variable of the same name. Link to comment Share on other sites More sharing options...
DuranDuran Posted September 21, 2017 Share Posted September 21, 2017 Thank you for the explanation. Link to comment Share on other sites More sharing options...
Recommended Posts