Please help me understand this very basic concept? Overlapping pickles.

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Lest say you have two types of objects, A and B.

    Lets create a different number of each. Then, lets toss 'em in a layout, with a good number overlapping each other.

    and have the following event:

    On start of Layout

    A is Overlapping B

    --- Set A position to B

    Now, on one hand, I'd naively expect every A to be aligned to a B that it was overlapping, but I'm smart enough to know that won't nec be the case. It tends to work with predictably even pairings, but at other times it the pairing won't be accurate, and there will be a few A moved to a B that wasn't being overlapped by that A.

    This concept translates to any situation where you need A to respond to a specific data on B or reverse. such as:

    A is overlapping B

    --- A set instancevariable to B.somVar.

    //A will not nec have the value of the B that it was overlapping.

    Can someone tell me what exactly is happening behind the scenes that results in... the mixed results we see in this situation?

  • It’s fairly simple. “A is overlapping B” will pick any A’s and B’s that overlap. It’s not a loop, it will just pick the ones that overlap and passes on to the next condition. If you want to examine individual pairs you’d need two for eaches.

    For each A
    A overlaps B
    For each B

    As to what the set position action is doing. It’s basically this with the picked instances.

     for(i=0; i<A.length; i++)
     A[i].setPosition(B[i%B.length])

    Or in other words it moves the first A to the first B, second A to second B, and so on. If it runs out of B’s it just loops back to the first B again.

  • For the explanation, that is what I thought, but I can create scenarios where each A has a B pair, and for some reason several A will be moved to the same B, leaving several B oh so lonely.

    Its possible that somehow the order of b in the list isnʻt being preserved in the order they are added, Let me see if I can get a demonstration capx built.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I believe instances are ordered and processed by their z-index. So A with the lowest z-index will be moved to B with the lowest z-index, and so on.

  • I believe instances are ordered and processed by their z-index. So A with the lowest z-index will be moved to B with the lowest z-index, and so on.

    Do you know why it is ordered according to z? Seems like it would be easier to leave in unordered from a performance/lazy standpoint.

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