theoretical question on for each and scanning through class

This forum is currently in read-only mode.
  • How can I do this :

    I have a bunch of identical sprite randomly placed on screen and I want to perform an action on all the sprites that are touching one specifically picked sprite in the group.

    I can do a "for each" to see which sprites are touching the selected one, but how can I perform an action on them?

    if I do something like this:

    +ball is "selected" (I switch a variable from 0 to 1)
    ->+for each "ball" object
    ->->+"ball" is overlapping "ball"
    ->->->+Do something to ball
    [/code:2i12b1dj]
    
    As you can see this results in an horrible mess and i'm not sure anymore which instance of ball object is being tested and which one is being acted upon.
    So am I missing something? Is there an easy way to scan through all the objects related to a particular object of the same category and operate on these related objects?
  • Use a family. If the balls are in a family, you can use conditions in the family to pick a different set of objects.

    For example:

    + MyFamily 'selected' = 1

    + Ball overlaps MyFamily

    -> Do action on ball

    In the actions, "Ball" relates to the objects overlapping the selected instance, and "MyFamily" relates to the object with selected = 1.

  • I'll look into it, thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've had a similar picking issue! Now I see why families are awesome. Thanks

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