Trigger Once (Culling Optimization)

0 favourites
  • 6 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • 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.

  • 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

  • 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.

  • 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 <img src="smileys/smiley2.gif" border="0" align="middle">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

  • 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...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)