bearkin333 Posted August 4, 2015 Share Posted August 4, 2015 Hello there again. I'm making good headway on my project, but as it grows, I find myself needing to not only split the code into separate files, but start using a State Manager. I set out to do these things, but I've run into an obstacle I did not expect. I'm trying to make a different .js file for each state I use, and I include those in the main .html file that houses the game via the <script> tag at the top. However, due to this, my state files are having trouble figuring out where the ThisGame object is. Here's my main code, split into the pieces that should matter. var game = new Phaser.Game(DEFAULT_GAME_WIDTH, DEFAULT_GAME_HEIGHT, Phaser.AUTO, ''); ThisGame = {}; window.onload = function() { game.state.add('levelSTATE',ThisGame.levelSTATE); game.state.add('overview_menuSTATE',ThisGame.overview_menuSTATE); game.state.start('levelSTATE');}; And the file for the levelstate, with the functions stripped for clarityThisGame.levelSTATE = function(){ };ThisGame.levelSTATE.prototype = { preload: function() { }, create: function() { }, update: function() { }}By all accounts, this should be working perfectly, but levelSTATE says that ThisGame was never defined. I guess there's something about the nature of everything in this scenario that I don't understand, but can anyone give me some pointers on what I'm doing wrong? Link to comment Share on other sites More sharing options...
Raiper34 Posted August 4, 2015 Share Posted August 4, 2015 Btw why do you use thisgame global variable? You do not need to do it.... States are "global" you can call it everywhere. Link to comment Share on other sites More sharing options...
bearkin333 Posted August 4, 2015 Author Share Posted August 4, 2015 It's really frustrating when problems that I've been wrestling with for hours have an easy, ridiculous fix.All the examples I'd seen with state managers used a "BasicGame" thing to add the states too - but they were also really old. Thanks. Just removing that fixed everything. Link to comment Share on other sites More sharing options...
Recommended Posts