Android Question How to snap to grid with image?

Scantech

Well-Known Member
Licensed User
Longtime User
Im struggling with this one. I used to have the code to make an image snap to a grid line. Im trying to duplicate it but the below code is not working.

B4X:
Private Sub Panel1_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
              
    Panel_Move(ACTION, x, y)

    Dim i2, i3 As Int
  
    If ACTION = ACTION_DOWN Then
        Log("DOWN")
      
        tmrTime.Enabled = True
      
        If blnSnaptoGrid = True Then
            i2 = x
            i3 = y
          
            downx = Floor(((x / 10) + 0.5) * 10)
            downy = Floor(((y / 10) + 0.5) * 10)
          
            innerView1.Left = Floor(((innerView1.Left / 10) + 0.5) * 10)
          
            innerView1.Top = Floor(((innerView1.Top / 10) + 0.5) * 10)
              
        Else
            downx = x
            downy = y
        End If

        Log("DownX: " & downx)
        Log("DownY: " & downy)
              
    Else If ACTION = ACTION_UP Then
        Log("UP")
        blnAllowMove = False
        tmrTime.Enabled = False
        destroyobjects
    Else if ACTION = ACTION_MOVE Then
        Log("MOVE")
      
        If blnAllowMove = True Then
          
            If blnSnaptoGrid = True Then
                              
                i2 = x
                i3 = y
              
                i2 = Floor(((i2 / 10) + 0.5) * 10)
                i3 = Floor(((i3 / 10) + 0.5) * 10)
              
                innerView1.Left = ((innerView1.Left + i2) - downx)
                 innerView1.Top = ((innerView1.Top + i3) - downy)

            Else
                innerView1.Left = ((innerView1.Left + x) - downx)
                  innerView1.Top = ((innerView1.Top + y) - downy)      
            End If
          
          
            panel1.Left = innerView1.Left
            panel1.Top = innerView1.Top
                                  
         End If
  
    End If
  
    Return True
End Sub
 
Top