jalex Posted November 4, 2017 Share Posted November 4, 2017 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? Quote Link to comment Share on other sites More sharing options...
labrat.mobi Posted November 4, 2017 Share Posted November 4, 2017 Object pooling is a must. Don't create new objects unnecessarily. You can use object pool for anything from bullets, enemies, explosions, etc.. jalex 1 Quote Link to comment Share on other sites More sharing options...
jalex Posted November 4, 2017 Author Share Posted November 4, 2017 Aha thanks for the reply and nice picture! Never really thoght of pooling until I noticed it started lagging. So time for some "re-coding" then. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 5, 2017 Share Posted November 5, 2017 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. jalex 1 Quote Link to comment Share on other sites More sharing options...
away168 Posted November 10, 2017 Share Posted November 10, 2017 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. jalex 1 Quote Link to comment Share on other sites More sharing options...
jalex Posted November 10, 2017 Author Share Posted November 10, 2017 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. 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.