How do I recognize clicks only on visible part of sprite

Get help using Construct 2

Post » Fri May 13, 2016 2:11 pm

Hi. In my apps I encountered a problem with Sprites behind other sprites or tiled backgrounds. I use them to hide scrolling elements/text behind the logo and have usually on top and bottom a tiled background on top layer. Now the problem is if a button/sprite is behind it clicks are still recognized. So I added a check for "sprite is overlapping background" before a link is executed. But now if a big image is only a few pixels behind the background no clicks are recognized anymore. Does anyone know a good solution for this? So that the visible part of a sprite is clickable (open link/page etc.) and the invisible part behind another object is not reacting to clicks or touch.

As a small workaround to show if a link is active I added another sprite on top to show if the link can be clicked but this is not a great solution.

Example:
Image Clickable:
http://www.fotos-hochladen.net/uploads/c2clickabledscxfn2yq5.png
Image not Clickable (few pixels behind the tiled background on top):
http://www.fotos-hochladen.net/uploads/c2notclickablejd4ztr3f9x.png
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Fri May 13, 2016 4:24 pm

Bring whats clickable to dedicated layer ? Filter out whats not on that layer after a click ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon May 16, 2016 7:58 am

But this will not fix the problem with the overlay that prevents scrolling text to be above the UI (the tiled background on top layer)?
It should be clickable evertime any part of the sprite is visible but the hidden parts behind the tiled background on top should not be clickable.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Mon May 16, 2016 8:18 am

You should really rethink everything you're doing - a better way to do it would be to have all your buttons in a family, and enable/disable them using variables whenever you see fit.

That being said, if you want a quick fix you can try to resize your picture's collision box.
B
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » Mon May 16, 2016 1:06 pm

I think you did not understand my problem. Its not about the static collision box. The collision box is the whole image but when the image is partially hidden behind the UI (global layer) the hidden part should not recognize clicks.

PS: Text objects dont have a collision check and I added invisible hotspots (sprites) for hyperlinks above them.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Mon May 16, 2016 4:28 pm

I understand the your problem (now). Still, it would be nice if you gave a dummy capx with just the problem. I am sure someone will work on it.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon May 16, 2016 4:50 pm

Single event

is clicking/touching image
is not clicking/touching UI (inverted is touching UI)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592

Post » Mon May 16, 2016 5:43 pm

This could be it!
Sometimes you just miss the easy solutions. I will try if this works. Thanks. :)

edit: just remembered that on touch is a single event and does not allow 2 single triggered events at once. But I will take a look at it.
edit2: It seems to work! :D
Thank you very much. I will do more testing later. :)
Image
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Tue May 17, 2016 5:05 am

Your welcome 😊

Occasionally the old KISS approach is still best 😁
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests