How do I find two sprites and only overlap eachother?

Just started using Construct 2? Post your questions here

Post » Wed Nov 19, 2014 8:35 pm

I want to find sprites that overlap just one other sprite (my sprites are called XSquare in my code). I tried the "for each XSquare" approach pictured below, but it doesn't select anything. How can I find the set of all XSquare objects that only overlap one other XSquare object? (I can find all the ones that overlap, but not all the ones that just overlap one).

Thanks for your time.
You do not have the required permissions to view the files attached to this post.
B
34
S
8
G
3
Posts: 169
Reputation: 3,305

Post » Wed Nov 19, 2014 11:11 pm

Hi winkr7. It looks like you're using a global variable (overlap) which will keep a running total of all of your overlaps.
I'd suggest you try using an instance variable instead so that the counter will give you an indication of how many overlaps each XSquare has. Then you can do a condition based on this being equal to exactly 1.
Hope that helps.
Image
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

Post » Wed Nov 19, 2014 11:24 pm

Hundredfold I appreciate the suggestion, but it is an XSquare variable--I think the problem has to do with how to compare one XSquare with many XSquare--how does it know to limit the first to one single instance and then the next reference to XSquare is every other instance?

But thanks for you comment.
B
34
S
8
G
3
Posts: 169
Reputation: 3,305

Post » Wed Nov 26, 2014 4:13 am

Hopefully this will help. It uses 2 families and counts the number of overlaps between the sprites using For loops. Use the mouse to drag them around the screen and the number of overlaps for each is shown on a text object. The event sheet is quite straight forward - but depending on your application, it might be worth limiting the frequency of the check (I have it as every tick, but if you have a lot of sprites then the overhead will be quite large).
You do not have the required permissions to view the files attached to this post.
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,251
Reputation: 46,476

Post » Wed Nov 26, 2014 10:46 pm

Thankyou very much colludium. I will look this over.

yours
winkr7
B
34
S
8
G
3
Posts: 169
Reputation: 3,305


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 7 guests