Workaround For Control Layering

0 favourites
  • 14 posts
  • I've read that native controls (buttons, scrollbars, etc) automatically get layered over sprites, and apparently there's no way to override this. I'm trying to determine if a touch takes place within a region defined by a sprite, even if the sprite is not the frontmost object (because a button is frontmost and overlapping the sprite).

    In other languages I've used a within() function to tell whether a click/touch takes place within the rect of an object, or a defined region on the screen -- basically, if an x,y point falls within a rectangle. How is this done in Construct? Do I have to compare the X and Y values of the touch separately?

  • I've read that native controls (buttons, scrollbars, etc) automatically get layered over sprites, and apparently there's no way to override this. I'm trying to determine if a touch takes place within a region defined by a sprite, even if the sprite is not the frontmost object (because a button is frontmost and overlapping the sprite).

    In other languages I've used a within() function to tell whether a click/touch takes place within the rect of an object, or a defined region on the screen -- basically, if an x,y point falls within a rectangle. How is this done in Construct? Do I have to compare the X and Y values of the touch separately?

    netdzynr I'm not sure if I understood your question properly but it sounds like you can use the Condition from the "Touch Plugin" which is >>>

    -is touching object(choose your object here)

    or

    if you wanna check the negative

    -is touching object(choose your object here)<<<<<Inverted

    Example:

    see here the Green object even if is behind the Orange object and you touch it will flash, doesn't matter how many objects are on top of it will still register the touch on the green object you can easily check if touched a region like you said with a rectangular object can be invisible too will not affect the touch

    https://www.dropbox.com/s/8wltup956z2ivs6/TouchObject.capx?dl=0

  • Thanks for this, but unfortunately when overlaying a button on top of the objects, the button grabs the touch event and your player object doesn't respond. Even if the button is disabled in the editor, the touch event still seems to be blocked.

    This is why I'm wondering if there's some other way to simply test whether the touch/mouse falls within the rectangle occupied by the sprite (or the region on the screen).

  • Thanks for this, but unfortunately when overlaying a button on top of the objects, the button grabs the touch event and your player object doesn't respond. Even if the button is disabled in the editor, the touch event still seems to be blocked.

    This is why I'm wondering if there's some other way to simply test whether the touch/mouse falls within the rectangle occupied by the sprite (or the region on the screen).

    Haah I see what you mean now

    will this work for you?

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

  • tarek2

    I think that will work, thanks. The method is "cheating" a bit because if a portion of a button falls outside of the rectangular region of the sprite, the sprite is still triggered, but this is probably good enough for now. Perfect that multiple instances of the button will trigger the sprite as this will be my situation: multiple buttons stacked on top of each other, stacked on top of a sprite.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • tarek2

    I think that will work, thanks. The method is "cheating" a bit because if a portion of a button falls outside of the rectangular region of the sprite, the sprite is still triggered, but this is probably good enough for now. Perfect that multiple instances of the button will trigger the sprite as this will be my situation: multiple buttons stacked on top of each other, stacked on top of a sprite.

    if I understood properly unless the button is inside the rectangles parameters will not trigger yess?

    Now That I understand exactly what you trying to do I can give you a different option

    1-https://www.dropbox.com/s/ke8jw46fep8ox6w/TouchObject3.capx?dl=0

    2- https://www.dropbox.com/s/nh2z6tstlabi1o6/TouchObject4.capx?dl=0

  • tarek2

    Thanks once again. By looking at your example files, I was able to get a solution that seems to work.

    The goal was to make a sprite respond to a touch/click action, regardless of whether a button appears on top of the sprite. But interaction should only occur within the rect of the sprite. I used the Bbox properties of the sprite to establish the active (clickable) region for any button. You'll see that when a click occurs within the rect occupied by BOTH the sprite and the button, the trigger takes places. No trigger occurs when clicking outside the rect of the sprite. So this effectively acts a way to make the sprite react even when a button is overlaid on top of it.

    Construct 3 project

    https://www.dropbox.com/s/wxpwp0ms6ozmk ... d.c3p?dl=1

    Thanks again for your helpful projects.

  • tarek2

    BTW, I wasn't able to find a way to combine the sprite touch and the button click into a single "or" event. Is this not possible because they are two different types of triggers? Like:

    zone is touched

    OR

    button is clicked

  • tarek2

    Thanks once again. By looking at your example files, I was able to get a solution that seems to work.

    The goal was to make a sprite respond to a touch/click action, regardless of whether a button appears on top of the sprite. But interaction should only occur within the rect of the sprite. I used the Bbox properties of the sprite to establish the active (clickable) region for any button. You'll see that when a click occurs within the rect occupied by BOTH the sprite and the button, the trigger takes places. No trigger occurs when clicking outside the rect of the sprite. So this effectively acts a way to make the sprite react even when a button is overlaid on top of it.

    Construct 3 project

    https://www.dropbox.com/s/wxpwp0ms6ozmk ... d.c3p?dl=1

    Thanks again for your helpful projects.

    Upss That's too bad I understood wrong again lol <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> I thought that the button had to be inside the Zone, I see now that you were looking for the Touch (X,Y) specific coordinates jeje I guess I'm so slow motion, but slowly we getting there

    Glad you fixed man, well done

    [quote:1gjbipns]BTW, I wasn't able to find a way to combine the sprite touch and the button click into a single "or" event. Is this not possible because they are two different types of triggers? Like:

    zone is touched

    OR

    button is clicked

    Something like this maybe?

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

  • tarek2

    Please don't apologize! I'm grateful to receive your help, and your projects have been useful for me to better understand Construct.

    The example you posted is the right combination of triggers, but I was hoping to combine them so that only one function call was required, instead of two. Logic like this:

    IF

    zone is touched

    OR

    button is clicked with additional conditions

    THEN

    call function

    If this is possible, the function isn't even necessary, since there could be single (flash) action.

  • tarek2

    Please don't apologize! I'm grateful to receive your help, and your projects have been useful for me to better understand Construct.

    The example you posted is the right combination of triggers, but I was hoping to combine them so that only one function call was required, instead of two. Logic like this:

    IF

    zone is touched

    OR

    button is clicked with additional conditions

    THEN

    call function

    If this is possible, the function isn't even necessary, since there could be single (flash) action.

    Mmmm it shouldn't call twice is an "Else condition" >> it Runs the top condition or the Else if the previous condition didn't meet the condition, I'm gonna have to check now in the meantime

    Much better solution you save checking the extra conditions

    https://www.dropbox.com/s/52pvsg9tt3v4cg7/TouchObject6.capx?dl=0

  • [quote:2hv0qkxu]but I was hoping to combine them so that only one function call was required, instead of two.

    netdzynr is working fine on my end have a look again I added a Debug Txt to show the Function calling Times

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

  • Yes! Version 6 of your example is perfect. "Overlapping (Mouse.X, Mouse.Y)" is the equivalent of a point within() function.

    This is all I meant by no function needed -- just one action:

    https://www.dropbox.com/s/z19l9ypm2xx2d ... 2.c3p?dl=1

    Thank you so much! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

  • Yes! Version 6 of your example is perfect. "Overlapping (Mouse.X, Mouse.Y)" is the equivalent of a point within() function.

    This is all I meant by no function needed -- just one action:

    https://www.dropbox.com/s/z19l9ypm2xx2d ... 2.c3p?dl=1

    Thank you so much! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Cool no problem mate, glad you found the solution

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)