How do I stop touch conditions to overlap with each other?

Get help using Construct 2

Post » Tue May 02, 2017 2:21 pm

What I intend to make:
On object 1 tapped -> Trigger event nr. 1
On object 2 tapped -> Trigger event nr. 2
What my issue is:
If object 1 is overlaping object 2, both events get triggered. How do i solve this?
B
10
S
4
Posts: 34
Reputation: 874

Post » Tue May 02, 2017 3:09 pm

add a new condition
if you right click on the events you will see an "invert" option.

on object 1 tapped
is not overlaping object 2 >>>> action
else >>>>> action

on object 2 tapped
is not overlaping object 1 >>>> action
Last edited by celstrider on Tue May 02, 2017 3:58 pm, edited 6 times in total.
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Tue May 02, 2017 3:10 pm

Turaco wrote:What I intend to make:
On object 1 tapped -> Trigger event nr. 1
On object 2 tapped -> Trigger event nr. 2
What my issue is:
If object 1 is overlaping object 2, both events get triggered. How do i solve this?


If both objects are overlapping how do you filter wich one to pick?? wich conditions do you use to filter it??

if you can post a capx will be easier to check
B
39
S
22
G
77
Posts: 285
Reputation: 42,686

Post » Tue May 02, 2017 3:15 pm

@Turaco see if this can help you, it picks the top object

https://www.dropbox.com/s/0guz0az3phrzuue/PickTopInstance.capx?dl=0
B
39
S
22
G
77
Posts: 285
Reputation: 42,686

Post » Tue May 02, 2017 3:25 pm

@Turaco You could do something like this, using the Zindex for each sprite:

https://www.dropbox.com/s/s9a857gm34hgv ... .capx?dl=0

It starts to get a bit complex if you have multiple sprites - you may have to shift the overlap check into a function and pass the UIDs.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue May 02, 2017 3:28 pm

@tarek2 - much simpler than mine, good call! :)
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Wed May 03, 2017 12:47 pm

mekonbekon wrote:@tarek2 - much simpler than mine, good call! :)


Thanks :)
B
39
S
22
G
77
Posts: 285
Reputation: 42,686

Post » Wed May 03, 2017 12:54 pm

Well it's not a solution because if they're not overlapping it will just pick the one with higher Z which isn't necessary the one I'm clicking on.

What I did was create a global variable "Touch_Enabled". After I click on something - > Touch_Enabled set to 0, wait 0.1 seconds -> Touch_Enabled set to 1.
My problem wasn't the overlapping actually. "Tap on object" already picks it only if its on top. The problem was when I click on Object 1 and it destroys my Object 1 = it triggers the Object 2 underneath it. Weird but whatever
B
10
S
4
Posts: 34
Reputation: 874

Post » Wed May 03, 2017 6:41 pm

Turaco wrote:Weird but whatever

Variables, use Instance variables and simply create a specific loop for events in whatever order.

Or if you have preference use greater than and sort of 'order' your objects from highest to lowest.

Variables fix all.

A capx would be handy.
B
7
S
1
Posts: 50
Reputation: 556

Post » Wed May 03, 2017 7:30 pm

ziadhorat wrote:
Turaco wrote:Weird but whatever

Variables, use Instance variables and simply create a specific loop for events in whatever order.

Or if you have preference use greater than and sort of 'order' your objects from highest to lowest.

Variables fix all.

A capx would be handy.


It wouldn't solve it. As I said before, even if I add "If Object 1 is overlapping Object 2 - inverted" it doesn't fix it. Because the event triggers after Object 1 is deleted on click, meaning the Object 2 is selected in the same tick
B
10
S
4
Posts: 34
Reputation: 874

Next

Return to How do I....?

Who is online

Users browsing this forum: AllanR, asdtricky, Yarfapet and 9 guests