When to check for collision?

Discussion and feedback on Construct 2

Post » Sun Jan 05, 2014 6:23 am

Hello everyone,

I was trying to optimize the performance of my game and I was wondering if you could give me some advice on when to check collision. Should I only check for collision (Player | On collision with Enemy) when enemy is on screen? Or it doesn't change anything. I was thinking that maybe it was checking for collision with all objects in the whole layout and that this practice could help performance.

Am I right or wrong? Do you have any advice about this?
Thanks!
B
33
S
9
G
3
Posts: 493
Reputation: 4,042

Post » Sun Jan 05, 2014 6:49 am

I wouldn't think it would impact the performance too much, even with a large amount of enemies in one layout, but that's one piece of coding that definitely wouldn't cause any problems if you tossed it in.

Better to err on the side of caution, I say.
B
15
S
4
G
1
Posts: 168
Reputation: 2,177

Post » Sun Jan 05, 2014 7:17 am

With the latest version of C2 you can check for collisions freely and the new collision cell optimisation system will ensure that performance is never hit too hard.

Essentially, it automatically does what you're worried about, restricting the scope of the collision checks to cells (which are the size of the screen) so that processing power isn't wasted checking for collisions that could never happen.

Read about it here.
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Sun Jan 05, 2014 8:02 am

Yea, but don't forget, that any instances switch collision check back. Read that blog post more closely.

To example: - > (event) if enemy is on screen
                     (sub event) if enemy collision with enemy - blah-blah-blah. - this is bad.

You need : (event) every 0.09 seconds
             (sub event) enemy is not on screen - > disable collision check. - das ist good )))



B
57
S
19
G
10
Posts: 191
Reputation: 9,606


Return to Construct 2 General

Who is online

Users browsing this forum: blackhornet, dwtiger, tarek2 and 2 guests