Jump to content

Reusing objects during game play, or using the new operator


jalex
 Share

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?

Link to comment
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.

Link to comment
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. 

Link to comment
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...
 Share

  • Recently Browsing   0 members

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