killer_manatee Posted October 4, 2017 Share Posted October 4, 2017 Hello. I'm trying to refactor my code into multiple files and create various stages. Here's how I do it: // game.js var bootState = require('./boot'); var loadState = require('./load'); var mygame = new Phaser.Game(800, 600, Phaser.AUTO); mygame.state.add('boot', bootState); mygame.state.start('boot'); export {mygame}; //boot.js import { mygame } from './game.js'; var bootState = { create() { mygame.physics.startSystem(Phaser.Physics.ARCADE); } }; export {bootState}; I've also tried changing boot.js to import { mygame } from './game.js'; var bootState = { create: function() { mygame.physics.startSystem(Phaser.Physics.ARCADE); mygame.state.start('load'); } }; export {bootState}; but that doesn't work either. I'm getting 'Invalid Phaser State object given. Must contain at least a one of the required functions: preload, create, update or render'. Thanks Link to comment Share on other sites More sharing options...
samme Posted October 4, 2017 Share Posted October 4, 2017 I think you may be exporting a wrapped/named value. Try instead export default bootState; Link to comment Share on other sites More sharing options...
killer_manatee Posted October 5, 2017 Author Share Posted October 5, 2017 Hi, I tried that but I'm still getting the same exact error Link to comment Share on other sites More sharing options...
samme Posted October 5, 2017 Share Posted October 5, 2017 console.log(bootState); killer_manatee 1 Link to comment Share on other sites More sharing options...
killer_manatee Posted October 5, 2017 Author Share Posted October 5, 2017 You were totally right about the first solution. The problem was that I forgot to change var bootState = require('./boot'); to import bootState from './boot'; Thanks! samme 1 Link to comment Share on other sites More sharing options...
bexphones Posted October 7, 2017 Share Posted October 7, 2017 Go to this there is a good template about . You need only to put the state in different files. It's all Link to comment Share on other sites More sharing options...
Recommended Posts