How do I setup touch conditions for overlapping sprites?

Just started using Construct 2? Post your questions here

Post » Tue Mar 18, 2014 8:26 am

overlappingregions.png


Hi there,

If I want to have two events setup to detect
1) user touched the green box
2) user touched anywhere in the red box that's not overlapping with the green box??

On touched "green box" -> do action 1

On touched "red box" -> do action 2


action 2 is always triggered when the green box is touched. How do I tell Construct2 to not "click through"?

Thanks
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 8
Reputation: 246

Post » Tue Mar 18, 2014 8:56 am

This is very tough since green and redbox are always overlapping.

I have a solution, which might not be best practice.

1. Change Action 2 event to
On touched "red box"
Not is in touch with "green box
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Wed Mar 19, 2014 11:34 am

Hi,

I actually have the same problem.

I tried your solution Rabenmutter but it is not working. My buttons simply just stop working :(.

I really need a solution for this since i create for android and i want to make my custom "Messages" which always overlays on the objects behind it.

Please some help! Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Wed Mar 19, 2014 1:26 pm

Try this:
Put both of them in a family.
Give family instance variable "Sprite Name".

On touched family
Pick top
--- If SpriteName == "green" -> Do action 1
---else -> Do action 2
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Thu Mar 20, 2014 4:59 am

Vuuv wrote:Try this:
Put both of them in a family.
Give family instance variable "Sprite Name".

On touched family
Pick top
--- If SpriteName == "green" -> Do action 1
---else -> Do action 2


What do you mean by "Pick top" ?
B
4
Posts: 8
Reputation: 246

Post » Thu Mar 20, 2014 6:34 am

Add Condition -> Choose Family -> Pick top/bottom (under Category Z Order)
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Thu Mar 20, 2014 9:07 pm

Code: Select all
Is touching "Green"
    Trigger Once
    : Do action 1
Else
Is touching "Red"
    Trigger Once
    : Do action 2
(a space before means its a sub event, the : means its the action)
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 21, 2014 4:42 am

Code: Select all
Is touching "Red"
    Is not touching "Green" > Do action 2
    Else > Do action 1


If you add the sub condition of not touching "Green" it would mean anywhere in the red area that isn't covered by green.


Here is a demo: (Warning: This file may induce seizures.)
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Sat Mar 22, 2014 2:03 am

Thanks all. I got it working after reading all the replies. The key is to use Is touching instead of On touched.
B
4
Posts: 8
Reputation: 246


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests