How do I limit mouse controls to topmost object?

Get help using Construct 2

Post » Sun Jul 19, 2015 10:46 pm

Example: I have a button that creates a window on layer "UI". I have a sprite that reveals an object on layer "Game" (below UI layer) when mouseovered. If the window is over the sprite, mousing over the sprite will reveal that object above the window. Thus, I'll see a random object obstructing my UI layer.

Example: I made a simple camera control setting based on clicking over the map and dragging. If I click this window and try to move it, I also trigger the camera function because the mouse is over the map, even though the window is in the way.

Example: I have a button that creates this window. I also allow the same button to destroy the window. If I move the window over the button to hide it, then click the button, the button still counts as clicked and destroys the window.
B
10
S
2
G
2
Posts: 73
Reputation: 1,044

Post » Mon Jul 20, 2015 6:04 am

The first example shouldn't be happening if the sprite object is on a layer below the UI layout. I would guess it's somehow getting moved, or created, on the same layer as the UI.

For the second example I would try to include a condition for the camera scrolling function that doesn't trigger it if the mouse is overlapping/dragging the window. I.e. "if click and drag + not dragging window -> move camera", This should stop the camera from scrolling if the window is being moved.

For the third example I'd try something similar to the second. "If button clicked + mouse not clicking window -> destroy window". This way if the button is obscured by the window, clicking in that area shouldn't push the button.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Mon Jul 20, 2015 6:42 am

One good way of handling modal UIs is to group actions that handle different "layers" into different event groups, and disable/enable them depending on what is showing. So if you have events for your main game, you disable them while the pause menu is showing, and re-enable them when you close it, for example.
B
10
S
2
Posts: 33
Reputation: 710

Post » Tue Jul 21, 2015 2:15 pm

@tgfcoder That sounds like a great idea, Thanks!
B
10
S
2
G
2
Posts: 73
Reputation: 1,044


Return to How do I....?

Who is online

Users browsing this forum: 25games, brunopalermo, Google [Bot] and 9 guests