Stop collision checks for instances off screen

Get help using Construct 2

Post » Fri Mar 07, 2014 7:17 am

If you have a ton of 1 object that has collision checks with it, is there a way to "disable" the checks when other instances are off screen so it doesn't use up resources?
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Fri Mar 07, 2014 7:29 am

"Is on screen" -> set collision enabled
X "Is on screen" -> set collision disabled
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 07, 2014 7:53 am

@7Soul - okay let me ask you this. Is that the same as putting a "if object is on-screen" collision check?
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Fri Mar 07, 2014 7:58 am

Right. He's trying to point out you can right-click on a second copy of your "if object is on-screen" event and hit 'invert.' This will be the equivalent to "if object is NOT on-screen" so you could use one event every second or so to enable the stuff on screen and one event to disable what is not on screen.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Fri Mar 07, 2014 8:02 am

Position checks are much quicker than collision checks.
If you have

-> On collision
Is on screen

You're first checking the collision, and THEN checking if it's on screen (events with a green arrow always run first).
By disabling collisions, those objects won't even be picked for the collision event

But if you want to be 100% sure, you can try both methods, and check the profiler in the debugger.
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 07, 2014 8:55 am

@7Soul - I had no idea triggers were played first regardless of hierarchy.

Do I need an else for the collision checks? (I'm going to have a bunch of them for various objects)
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Fri Mar 07, 2014 6:16 pm

Yeah you can use an else instead of inverting the condition, I guess it makes no difference.
The thing I said about hierarchy is only for when you can't move a condition on top of a trigger. You can make it a sub-event, in which case it won't be the first thing
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 07, 2014 6:41 pm

@7Soul - thanks for the help!
B
40
S
12
G
1
Posts: 532
Reputation: 4,147


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot] and 20 guests