Trigger Once (Culling Optimization)

Get help using Construct 2

Post » Thu Mar 22, 2012 5:50 am

I'm trying to make a system where objects that are not near the player are not created until they're needed - my game has a very small visible area around the player, so until enemies are right on top of him they don't need to have lots of extra sprites that are slowing the game down.

The idea I had was to have a Culling sprite around the player, and when it touched an enemy it spawned all the extras (i.e. a shadow), but at the moment it's spawning one shadow per tick, even though I have a "Trigger Once" condition (sometimes? it seems very flaky).

You can see the problem here.

Move with the arrow keys and try overlapping the pink "Culler" over the HTML5 icons, see the Shadow count skyrocket even though there's a Trigger Once condition.

and here's the Capx.

That's not even mentioning trying to delete an object when it's outside of the Culling sprite, which seems to be even more flaky. Am I approaching this problem the wrong way?

Thanks.

EDIT: The reason I ask is because I'm struggling to maintain a decent framerate in the game I'm building, so I need to find all the little ways to make it run as fast as possible. Perhaps I'm trying to do too much with C2, not sure yet. Here's what I have so far: Shadow test for zombie game. I'm getting about 50 fps in IE9 until a flare goes off, then it halves.Puck2012-03-22 05:58:42
B
32
G
1
Posts: 18
Reputation: 1,663

Post » Thu Mar 22, 2012 8:49 am

Maybe Trigger Once got confused because there are more than one ShadowCaster triggering the event ?

I'm not sure how to explain it, I'm kinda confused myself trying to understand how trigger once work in this particular case.

btw, I remove the trigger once condition and replace it with a boolean variable, (also adding a casterID to destroy the right shadow) and it sort of work :

http://dl.dropbox.com/u/39382262/TriggerOncePotato.capx

i hope that helps
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Thu Mar 22, 2012 10:09 am

Thanks Potato, that works how I wanted it to, good stuff! I don't quite understand 100% what's going on in your one as I haven't used instance variables before, but I'll figure it out. Thanks again.
B
32
G
1
Posts: 18
Reputation: 1,663

Post » Thu Mar 22, 2012 11:57 pm

Puck, i make a mistake on the example i posted above,
it happens when more than one ShadowCaster overlap the culler at the same time.

I still don't understand why either, I'm asking about it in here,
it confused the heck out of me:

http://www.scirra.com/forum/confusion-on-how-event-works_topic50372.html

sorry for using your capx for example, i hope you don't mind
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 12:25 am

Yeah no worries, that's why I made it. I tried implementing your previous solution in my game but it seemed quite buggy, often spawning more than one shadow per caster. When I get a chance I'm going to try using a distance check rather than a Culling sprite to see if that works any better, as I've had other issues with the "on overlap" being a bit flaky.

Thanks for the help Potato!

(Also I turned webgl on in my wip game and now I get a steady 60fps in chrome, so at the moment I'm going to ignore optimization and focus on gameplay).
B
32
G
1
Posts: 18
Reputation: 1,663

Post » Fri Mar 23, 2012 2:25 am

I know you got yours working, but in order to keep from using another sprite detector, you could do:

For Each Sprite(or family enemy ect...)
->Distance(you.x, you.y, Sprite.x, Sprite.Y)<100
-->Spawn whatever. Do whatever.
->Distance(you.x, you.y, Sprite.x, Sprite.Y)>=100
-->Destroy whatever. Do whatever Else

I dont know if it would make anything better or worse...
B
192
S
6
G
7
Posts: 213
Reputation: 10,178


Return to How do I....?

Who is online

Users browsing this forum: spacedoubt and 2 guests