Conditions Constantly being Called

Get help using Construct 2

Post » Tue May 07, 2013 10:23 pm

So in my game I have a condition that says,

     Player overlapping Fog
          do stuff

Question I have is, is that a Resource Hog? I think it might be, let me explain.

So If the player is in a Room (All Rooms have fog of same size of room) he would be triggering the above condition, so it is checking and/or doing stuff 60 times a second due to the Game Loop.

so is that bad? Should I add a Trigger Once somewhere? What is the best approach where you need to test if Player is overlapping X and then have it do stuff, but you don't want it to consume all the resources, maybe have it check after player moves instead of constantly?

thoughts.

Thank you.
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Tue May 07, 2013 11:00 pm

it depends on what are you trying to achieve? if you need the "do stuff" just 1 time you shuld restrict it
B
18
S
6
G
3
Posts: 197
Reputation: 4,129

Post » Tue May 07, 2013 11:10 pm

Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue May 07, 2013 11:26 pm

If the fog is like a rectangular area (i have 'zones' in my game), you can for each fog/zone check that the players x coordinate is between the fogs left and right edge x, and then the same for Y.

I used to do it with overlap, but with a bunch of objects than can move between all the zones, it could slow down.

the downsides are that the condition is met only when the players origin passes into the fog, also you can't rotate the fog without .. maths
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed May 08, 2013 1:58 pm

@Ashley, I agree totally with that article, it has actually helped me not be so picky in my code and just finish the project, but in this case I am not having those kinds of issues. I basically have a function that is constantly called, and 99% of the time no condition is met so I am calling it for no reason, in effect Memory Leak. I would think that could eventually drag down performance, like not killing sprites that go off screen, they will build up and eventually cause problems.

@keepee that is in effect what I am doing, but in stead of isPlayer within X/Y I just see if overlap. Not sure I see how between X/Y would really be different then onoverlap, can you explain a bit more? thank you.
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Wed May 08, 2013 2:05 pm

@jbmoyer - the whole point of that blog post is unless you can measure a performance impact, you are most likely wasting your time. Have you been able to measure that it affects performance in a significant way? Many events run surprisingly fast, so it may simply be of no concern at all - a totally insignificant impact on performance. It's also not a memory leak unless it keeps allocating more and more memory, which the ordinary use of events will never cause.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Wed May 08, 2013 4:12 pm

@Ashley, ok I understand that is a great point, if it cant be measured, and/or you cant see any impact to the app MOVE ON! :) ok thank you, much appreciated. I am MOVING ON! :)

Thanks
B
21
S
7
G
1
Posts: 128
Reputation: 3,076


Return to How do I....?

Who is online

Users browsing this forum: spcsmrf and 26 guests