Jump to content

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


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. 




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

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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