Thread
#compose
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    I've got yet another problem, sigh... I have a rectangle that covers the whole canvas. I am using detectTapGestures to detect presses. When I press somewhere within the rectangle, I only get success some of the time - it's really inconsistent. I have no idea what is wrong with my simple code. Any ideas? Code in thread.
    onPress = {
                            val x = it.x
                            val y = it.y
    
                            if(rect1.contains(x,y))
                            {
                                println("Success")
                            }
                        }
    k

    Kirill Grouchnikov

    1 year ago
    If you remove all the extra logic and just do
    println
    of coordinates, do you see it printing on every press, or does it skip presses?
    Is there any motion between down and up?
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    I can now see that there is an area that is always successful, and an area that is never successful. It seems as if the rectangle actually smaller than the tapdetection. I am wondering if the units used are the same. I think that my canvas is defined in pixels. What unit is used for touch input?
    Anyway, to answer your questions, yes, when I print everything, all works apart from the fact that the measurements do not seem to correspond.
    Hope I'm making sense. 😉
    So the x dimension of my rectangle/canvas is 1000f. If I click on the right side of it, the x coordinate is roughly 1397f. This means that the unit of measurement is different.
    What unit of measurement is used for touch input?
    Gabriel Melo

    Gabriel Melo

    1 year ago
    Are you sure your canvas is defined in px and not dp?
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    ok, never mind, my bad, I made a mistake. My touch inputs were covering the whole of my screen, not just my canvas. Thanks for your help! 😊