Picking All Similar Instances

0 favourites
  • 6 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I'm working on a stealth game, and what's a stealth game without secret passages that have to be discovered?

    As such, there will be Sprites that will fade to 50% opacity when the main character - FINN - overlaps them.

    I have two types of Sprites that I have put into a Family, called Passages. Since the level design will be set in a robotic facility of some sort, I plan to have at least two types of hidden passages (for example, a hidden passage that leads also to a vent shaft - a hidden passage in a hidden passage).

    Visualize a room with four passages; two on the left, two on the right, and where the first passage seems to end, there's a passage that continues on farther. Each passway is covered by multiple instances of a particular Sprite (this is so I can manage corners more effectively). When one instance of a Sprite goes transparent, all other instances IN THAT GROUP also go transparent, even if FINN is not overlapping them. It's AS IF those group instances are "one".

    So we have passage one (L1), the passage it connects to deeper in (L2), and the two on the right (R1 and R2).

    L1 uses Sprite 1 and has a Family instance variable labeled Group with a value of 1.

    L2 uses Sprite 2 with Group variable value of 2.

    R1 uses Sprite 2, value 3.

    R2 uses Sprite 2, value 4.

    Now, individually, I can get any group, regardless of which Sprite is used, to render transparent when FINN overlaps that group. My problem is when FINN overlaps two different groups simultaneously. Such as in my illustration here where one passageway connects to another passageway directly.

    I'm using an instance variable in FINN in the following way:

    FINN overlaps [instance of Sprite] ==>> Set FINN.Group# to Sprite.Group#

    PICK all Sprites where Sprite.Group# = FINN.Group# ==>> ......and so on.

    I recognize that this set up only allows FINN to recognize ONE passageway to be identified.

    And that's where I'm having my trouble. I need to have all applicable groups activated.

    Can someone suggest a solution, please? What am I not seeing? THANKS!

  • You could use a variable to temporarily store the current group as you loop over the passages you're overlapping like this:

    global number curGroup=0

    finn: overlaps passage

    for each passage

    --->set curGroup to passage.group

    --- pick all passage

    --- passage: group = curGroup

    ------> passage: set opacity to 50

  • R0J0hound - I thought I tried something like that earlier day, buuuut, maybe not THAT.

    I'll test out your example and see if that flies. Thank you, good sir... I'll get back to you if it still fails.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, maybe I'm not understanding how you described your suggestion above, but I'm not getting things to work.

    At best, I'm able to get groups of instances (when they're related by group #) to shift as I intend. BUT, when FINN is overlapping two groups that are side-by-side (such as what I attempted to describe in my OP), so long as FINN is overlapping the first group, the second group remains unaffected until FINN is no longer overlapping the first.

    And that's to say nothing of getting the groups to go back to opaque when FINN is no longer overlapping any instance of a group.

  • Sample:

  • You two are miracle-workers. That's exactly what I'm aiming for.

    I'll just adapt what you worked out to reference the Family object I have and swap out the instance variable for the local variable instead. I think what was throwing me, in particular, was the use of the Pick All system condition. That didn't make sense to me since I didn't want to go backwards (as it seemed) and select every instance yet again. But now that I see it on the Event Sheet, I believe I see the logic behind it now.

    Thank you both so much. You've always been patient and kind and supportive. GOD BLESS AND MERRY CHRISTMAS!

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