Do you have an "Always" section in your code that is always on?

0 favourites
  • 4 posts
From the Asset Store
This Girls Game allows young fashionistas to develop their taste and skills as a fashion designer.
  • When I create games in Construct I like to put my code in groups. When a group is no longer needed I disable it. I love that groups are collapsible and it just helps keep me focused.

    Sometimes, however, I will start something (like a fade or lerp movement) that would require a group to stay open. With my latest project I have created a group called "Always" for this code.

    Does anyone else do something similar? I'm not sure if this is a good practice, or if there is something else that would work better...

    EXAMPLE:

    I'm working on a word game. During the scoring sequence I initiate a bullet behavior on the letter tiles to make them fly up and then fall off the screen, with gravity. Then I disable the Scoring group.

    In my Always group I have this code:

    - If bullet behavior for [sprite] is enabled

    - set sprite.angle to sprite.angle + 12

    (This makes the letters spin as they fly off, which looks nicer.)

  • This seems like good practice, trying to lower the amount of stuff to process per tick.

    I do something similar, but haven't utilised group enabling/disabling - I usually use a top level event with an individual boolean like "IsActive", so then all objects do 1 check, and if some are active and some are not, this works well. Beyond this, there might be a sub event for a "IsLightweight", so that very minor things to check are checked, but if that is also false, then this means it's probably an important object that there aren't many of, so it'll check for some more heavier events for these objects.

    This is comparable to what you do with "is bullet behvahour enabled", but you could put some more stuff below here, such as "bullet is overlapping enemy", as you know you'll only care about detecting collisions if that bullet is active. HOWEVER, some events or conditions, such as collisions, really benefit from being a "top level" condition, because it let's it use collision cells, whereas having "is bullet enabled" first, would prevent collision cells from working, thus making performance worse. Best to just test this, make lots of bullets exist and compare CPU performance with different ordered events/conditions, you might be surprised by the results.

    Then ofcourse having groups helps when you use the debugger and can easily identify which groups need more attention to optimise.

    So overall, yeah, good job!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I generally put all my code into various functions, then just call the functions when needed.

    This has the same effect but also helps a great deal in organising and debugging the game.

    It also means my main game loop is very readable since its just a list of functions.

  • Can you put a break point in functions now? I tried to use lots of functions a ways back and could never set breakpoints.

    yours

    winkr7

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