Ninjadoodle Posted May 24, 2018 Share Posted May 24, 2018 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! Quote Link to comment Share on other sites More sharing options...
enpu Posted May 24, 2018 Share Posted May 24, 2018 @Ninjadoodle You should try to avoid creating new instances of class if not necessary, so i would choose to create one instance and then use it to show/hide the settings container. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted May 24, 2018 Author Share Posted May 24, 2018 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 Quote Link to comment Share on other sites More sharing options...
enpu Posted May 24, 2018 Share Posted May 24, 2018 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? Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted May 24, 2018 Author Share Posted May 24, 2018 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 Quote Link to comment Share on other sites More sharing options...
enpu Posted May 24, 2018 Share Posted May 24, 2018 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. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted May 24, 2018 Author Share Posted May 24, 2018 @enpu - Thanks for the clarification, this makes sense ... I'll try to go ahead and design with that in mind! Thanks heaps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.