October 26, 2024
Chicago 12, Melborne City, USA
Android

Allowing touch events to interact 2 layers at once


I’m not sure what to do about this, I have a framelayout that sdl uses for my native libraries, then I have a compose view over it for the ui (buttons and a thumbstick which gives W, S, A and D through sdl).

The compose view is full screen since all the buttons are dynamic and can be resizes and are draggable. This blocks touch from both layers in one direction.enter image description here
I added a picture to show what I mean, If I put my finger down on where it’s red, the framelayout, and leave it there I can look around and mouse look works and I can even interact with the thumbstick at the same time, both work simultaneously as long as I don’t remove my finger.

Now the other way doesn’t work, if I use the thumbstick or any buttons from the compose view I can’t interact with the sdl framelayout. Trying to mouse look simply does nothing.

    <FrameLayout
    android:id="@+id/sdl_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

       <androidx.compose.ui.platform.ComposeView
        android:id="@+id/compose_overlayUI"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|start"
        android:padding="16dp" />

And in my EngineActivity

        // Add SDL view programmatically
    val sdlContainer = findViewById<FrameLayout>(R.id.sdl_container)
    sdlContainer.addView(sdlView)

    // Remove sdlView from its parent if necessary
    (sdlView.parent as? ViewGroup)?.removeView(sdlView)
    sdlContainer.addView(sdlView) // Add SDL view to the sdl_container

val composeViewUI = findViewById<ComposeView>(R.id.compose_overlayUI)
    (composeViewUI.parent as? ViewGroup)?.removeView(composeViewUI)
    sdlContainer.addView(composeViewUI)
    composeViewUI.setContent {
        OverlayUI(

And all my button code is here.

What are my options?
Basically what I’m after is if there’s no button or ui element for your touch to interact with, the touch should be allowed to pass though to the sdl layer (red in the image)



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video