Jump to content

Sprite added to Group won't show up. Example Code Included


edmundep
 Share

Recommended Posts

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. 

 

Kyle

test.zip

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

  • 2 years later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...