Android Question Fling Gesture move object

wyatt420

Member
Licensed User
Longtime User
Hello, I am using AcceleratedSurface and GD Fling to fling an object (smiley) from the house.

Currently the smiley just arrives at the "Finger Up" position, but I would like to have the Smiley "travel" from the house to the final desired place.

Do you have any ideas on what the best way to achieve this? Also - if i wanted multiple Smileys.
thanks

B4X:
#Region  Project Attributes
    #ApplicationLabel: Fling v0.0
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Dim Surface As AcceleratedSurface

    Dim showDesired As Boolean
    Dim Desired As SB_Vector2D
   
    Dim smiley, house As Bitmap
    Dim GD As GestureDetector

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Adds an accelerated surface
    Surface.Initialize("Surface", True)
    Surface.Color = Colors.DarkGray
    smiley.Initialize(File.DirAssets, "smiley.png")
    house.Initialize(File.DirAssets, "house.png")
   
    Activity.Color = Colors.Black
    Activity.AddView(Surface, 0, 0, 100%x, 100%y - 40dip)
    GD.SetOnGestureListener(Surface, "Gesture")

    showDesired = False
    Desired.Initialize(Surface.Width / Density / 2, 10)
   
End Sub

Sub Activity_Resume
    Surface.StartRegularUpdateAndDraw(16)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Surface.StopRegularDraw
End Sub

Sub Surface_Update(ElapsedTime As Long)


End Sub

Sub Surface_Draw(AC As AS_Canvas)

    'Draw Smiley   
    If showDesired = True Then
        'AC.DrawCircle(Desired.Xdip, Desired.Ydip, 25dip, Colors.RGB(0, 0, 128), True, 0, False)
        AC.DrawBitmapAt(smiley, Desired.Xdip-smiley.Width/2, Desired.Ydip-smiley.Height/2)
    End If   
    AC.DrawBitmapAt(house, Surface.Width/2-house.Width/2, Surface.Height-house.Height)
End Sub


Sub Gesture_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
    Log("   onFling velocityX = " & velocityX & ", velocityY = " & velocityY & ", ev1 = " & MotionEvent1 & ", ev2 = " & MotionEvent2)
    Log("      X2, Y2 = " & GD.getX(MotionEvent2, 0) & ", " & GD.getY(MotionEvent2, 0))   
    Log("x2 = " & (GD.getX(MotionEvent2,0)/Density) & " ,y2: " & (GD.getY(MotionEvent2,0)/Density))
    showDesired=True
    Desired.X = GD.getX(MotionEvent2, 0)/Density
    Desired.Y = GD.getY(MotionEvent2, 0)/Density
    
End Sub
 
Top