Should we pool objects in games?

Discussion and feedback on Construct 2

Post » Mon Jan 07, 2013 5:43 pm

I read Ashley's really good article at http://m.netmagazine.com/tutorials/make-your-javascript-apps-smoother . He suggested avoiding creating objects too often in Javascript.

My question is, at a higher level, in Construct2, should we also be avoiding creating/destroying too many sprites on the fly and instead have a "pool" of them that we can re-use?

A good example are bullets, which get created and destroyed very often.

Obviously the answer might be "depends", I just wanted to make sure there is nothing in the Construct2 engine already doing the "pooling" of sprites and objects for us.

Thanks!
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

Post » Mon Jan 07, 2013 6:12 pm

I believe C2 already does the pooling for you, and that's how @Ashley managed to improve the performances of the engine over the releases.

Creating a lot of objects at once every tick will take a hit on performances though, but managing a pool of objects to reuse seems like overkill for, I believe, C2 already handles it at runtime.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,786

Post » Mon Jan 07, 2013 7:00 pm

Kyatric sounds correct here - I noticed this little performance bonus the other day where I have a sprite that explodes and creates lots of little shrapnel pieces, each one a little 6x6 sprite. The first time it runs the browser drops pretty heavily in FPS for half a second. But after that, despite having destroyed the sprites and creating them again in C2, I no longer get the frame-drop of creating them. I was considering adding in a pre-cache step on layout start that generates a bunch of sprites that I know I will need, like my shrapnel sprites, but I wasn't sure if this was a good idea or not.
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Thu Jul 25, 2013 8:28 pm

@Kyatric, I found this topic searching for "pool" since I was wondering if I needed to do this or if construct already did. Now, you don't sound 100% sure that construct does this. Could you confirm? Or maybe @Ashley can confirm?

Thanks.
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Thu Jul 25, 2013 10:59 pm

@MakubeX: Since this old thread (jan 2012) Ashley wrote a blog article about how he handled garbage collection in JS/C2.

So yes it is confirmed that C2 does recycle objects and as far as performances go everything you need to care about is gathered in the performance tips manual article and you can also check this, and that blog articles for a little more insight.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,786

Post » Thu Jul 25, 2013 11:33 pm

Thanks for clarifying, @Kyatric.
B
12
S
3
G
3
Posts: 36
Reputation: 3,048


Return to Construct 2 General

Who is online

Users browsing this forum: TheRealDannyyy, Zonacas and 14 guests