edmundep Posted October 2, 2014 Share Posted October 2, 2014 Hey guys, I've been fighting with this for a few hours. I looked at all the examples on how to build a game with groups and add sprites to them.The examples work great but my code doesn't. The difference between my code and the examples is mine uses State classes. this.game.state.add('Boot',Boot); etc I have attached example code. The top game is using the example code and works great. The bottom one when you scroll shows a black canvas with no sprites. I have no idea why! Would appreciate the help as I am pretty new to phaser. but can't seem to find anything wrong with what i'm doing. Kyletest.zip Link to comment Share on other sites More sharing options...
j0hnskot Posted October 2, 2014 Share Posted October 2, 2014 This is because you add the group in the boot state. Changing a state destroys display object, as a result your group too (there is a chance i may be wrong with this). Add this in your create function of MainMenu state instead of boot and it will work : this.game.mainStage = this.game.add.group(); Extending the game object with no reason i don't think it's a good idea. Better use something like this.mainStage to make mainStage a property of MainMenu object. edmundep 1 Link to comment Share on other sites More sharing options...
edmundep Posted October 2, 2014 Author Share Posted October 2, 2014 YES! thanks j0hnskot Small over sight, i didn't realize states wipe everything i thought the group was global constant.. Knowing that, you are correct, i don't need to bind the mainStage to the game. I can just use this.mainStage. Thanks for the answer!Kyle Link to comment Share on other sites More sharing options...
Domdom15 Posted January 27, 2017 Share Posted January 27, 2017 Can I pass group as a parameter while changing states and then access that group in the next state? If so please can someone tell me how? Link to comment Share on other sites More sharing options...
Recommended Posts