Sign in to follow this  
Ninjadoodle

Whats the best way to make a settings menu?

Recommended Posts

Hi @enpu / Panda people :)

Just wondering what the best way to approach a settings menu would be ?

Basically I have a little settings button (cog), in the top right of my level. When you click the button, the settings menu shows (screen goes black and shows some buttons).

I am creating the settings menu in a separate container over the top of the stage.

Is it a good idea to create the settings menu class on the settings button click and destroy it when the back button is pressed, or is it better to create it as the start of the stage and just show/hide it?

Thanks for any feedback!

Share this post


Link to post
Share on other sites

Hi @enpu

Thanks for the tips! So, just to clarify - for enemies / bullets etc. I'd create new instances from a class, but for any items that don't need to be destroyed, it's better to show/hide instead?

Just want to make sure I do it right going forward :)

Share this post


Link to post
Share on other sites

How to use classes and when to create new instance and when not really depends on a situation, so there is no really one right answer to that.

The only thing that you should look for, is that you are not generating too much garbage, because that can cause performance issues.

Is JavaScript garbage collection familiar thing to you?

 

Share this post


Link to post
Share on other sites

Not really :( I'm kind of learning this as I go - so  I make a lot of mistakes. I'll have a look into garbage collection. I guess this is where pooling comes in handy? I've always wondered what it was for :)

Share this post


Link to post
Share on other sites

You are not making mistakes here. In this case both ways probably work just as well, meaning the best way would be the one that looks best for you. A good rule of thumb would be to avoid creating new instances as much as possible.

About garbage collection..

Basically when you create object in JavaScript (like new instance of class) and store it into variable, then if at some point there is no way to access that object anymore or you overwrite the variable with another object, that previous object becomes garbage because it can't be used anymore.

Then from time to time JavaScript cleans all the garbage from memory, and if there is a lots of garbage, it can cause small pause in your game.

Note that this is really an issue only when there is so much garbage that the pause becomes noticeable.

Share this post


Link to post
Share on other sites

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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.