Sign in to follow this  
jalex

Reusing objects during game play, or using the new operator

Recommended Posts

When programming my HTML5 2d game I noticed that using the new operator during game play can be quite expensive sometimes if many objects are created. So I wonder what is good practice here? When you implement your game do you always create the objects that are going to be dynamically used from start (for objects such as particles, ammunation, explosions etc), and then reuse them during game play?

Share this post


Link to post
Share on other sites

Yeah, its  an optimisation thing so really you should have decent tests in place to make sure that its working as intended, but, I think with object pooling most peeps just take the opinion that they're going to run into issues without it at some stage so start out with object pooling in mind.

Share this post


Link to post
Share on other sites

Just an addition, basically just realize the amount of objects you have. For example, a bullet hell game needs tons of bullets, but they're all the same, that's when your mind should come up with object pool. The rest can go over later. Just make sure you know your game design, then scale from it. Not everything always need a pool (or the pool count must be quite precise) cause you may run out of memory there especially in low-end mobile device, so use it wisely.

Share this post


Link to post
Share on other sites
2 hours ago, Alectora said:

Just an addition, basically just realize the amount of objects you have. For example, a bullet hell game needs tons of bullets, but they're all the same, that's when your mind should come up with object pool. The rest can go over later. Just make sure you know your game design, then scale from it. Not everything always need a pool (or the pool count must be quite precise) cause you may run out of memory there especially in low-end mobile device, so use it wisely.

Thanks for the advice! Yeah I have noticed when programming the last few days that perhaps not all "new" need to be removed. I have got some bonus items that appears now and then that I will not use a pool for, but then I have a weather effect with hundreds of new objects, so there I used a pool. It made a difference. 

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.