Android Question How do I know if a drawn line is within the bounds of a button?

Servaas

Member
Licensed User
Hello all, trying my hands on a little line drawing game, and I have it working but now i'm trying to see if X is within the bounds of a button I have placed in Designer.

B4X:
If x > Button1.Top Then
        If x > Button1.Left Then
            If x < Button1.Top + 20 Then
                If x < Button1.Left + 60 Then
        Button1.Visible = False
        End If
      End If
    End If
End If

This does not work apparently. I guess I can see why (I think) but I'm unsure how to correct it. The line is drawn from the top of the screen by the way.
 

Servaas

Member
Licensed User
This seems to solve it... i'm very sorry if it looks like i'm spamming this board but I am very much starting up again in basic so little rusty.
B4X:
If NeedlePointx > Button1.Top Then
        If NeedlePointx > Button1.Left Then
            If NeedlePointx > Button1.Left + 60 Then
                If NeedlePointx < Button1.Top + 20 Then
                Button1.Visible = False
                End If
             End If
        End If
End If
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would suggest you this code:
B4X:
If NeedlePointx > Button1.Top Then
    If NeedlePointx > Button1.Left Then
        If NeedlePointx < Button1.Left + Button1.Height Then
            If NeedlePointx < Button1.Top + Button1.Width Then
                Button1.Visible = False
            End If
         End If
     End If
End If
And be careful: If NeedlePointx < Button1.Left + Button1.Height Then
< instad of >!
 
Upvote 0
Top