theoretical question on for each and scanning through class

For questions about using Classic.

Post » Thu Mar 05, 2009 11:33 pm

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:
[code:2i12b1dj]+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?
B
3
S
1
G
3
Posts: 45
Reputation: 1,140

Post » Fri Mar 06, 2009 12:51 am

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Mar 06, 2009 3:24 am

I'll look into it, thanks.
B
3
S
1
G
3
Posts: 45
Reputation: 1,140

Post » Fri Mar 06, 2009 8:10 am

I've had a similar picking issue! Now I see why families are awesome. Thanks ;)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests