Android Question LibGDX Texture Drag&Drop


New Member
Licensed User
Longtime User
Hello everybody

i'm new to libGDX and of course like any beginner i started to play around with others code

I stop at this example "lGDX_Perf_Smileys" made by "Informatix" and modify it a bit and i was wondering if in this example i have any chance to drag and drop this drawings(smileys)?

so basically we have
-a set of coordinates wrapped in a type()
-a batch do draw a texture over the coordinates given by the type
I've studied some other examples of drag and drop in libGDX and all of them use a World(lgBox2DWorld) and actors or Bodies(lgBox2DBody) witch i don't know how to implement so far.

So the question is : is there any chance to implement a drag&drop function in the given code without re-writing the whole code?

Sub Process_Globals
   Type typSmiley(X As Float, Y As Float, dX As Int, dY As Int, Color As lgColor)
   Dim timer1 As Timer
End Sub

Sub Globals
   Dim Stage As lgScn2DStage
   Dim lGdx As LibGDX
   Dim GL As lgGL
   Dim Batch As lgSpriteBatch
   Dim Camera As lgOrthographicCamera
   Dim texSmiley As lgTexture
   Dim lstSmileys As List
   Dim Quantity As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.Title = "libGDX - Performance"
     Dim Config As lgConfiguration
       Config.useAccelerometer = False
       Config.useCompass = False
       Config.useWakelock = True
   'Creates the libGDX surface
End Sub

Sub Activity_Resume
   'Calls the Resume method of libGDX
   If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

   If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Create
   'Initializes the sprite batcher
     'Initializes the number of smileys
   Quantity = 1
     'Initializes the timer
   timer1.Enabled = False
End Sub

Sub LG_Resize(Width As Int, Height As Int)
   'Sets the camera viewport
End Sub

Sub timer_Tick
   If lstSmileys.IsInitialized  Then
     Dim MU As lgMathUtils
     Dim Smiley As typSmiley
     Smiley.X = (Stage.Width / 100) * 20
     Smiley.Y = (Stage.Height /100) *90
     Smiley.dX = 0
     Smiley.dY = -2
     Smiley.Color.SetRGBA(MU.RandomFloat2(0.2, 1), MU.RandomFloat2(0.2, 1), MU.RandomFloat2(0.2, 1), 1)
     Quantity = Quantity +1
   timer1.Enabled = False
   End If

End Sub

Sub LG_Render
   'check the limit of the smileys to be draw
   If Quantity < 80  +1 Then
     'if less than desired then continue
       timer1.Enabled = True

       'else timer.stop
       timer1.Enabled = False
   End If

   'Clears the screen and colors the background in blue
   GL.glClearColor(0, 0, 0.4, 1)

   'Updates the matrices of the camera

   'Uses the coordinate system specified by the camera
   Batch.ProjectionMatrix = Camera.Combined

     'Updates the position of smileys

     'Draws the smileys with their new position
       Dim Smiley As typSmiley
       For i = 0 To lstSmileys.Size - 1
         Smiley = lstSmileys.Get(i)
         Batch.Color = Smiley.Color
         Batch.DrawTex2(texSmiley, Smiley.x, Smiley.y, 64dip, 64dip)
   End Try
End Sub

Sub LG_Update
   'Computes the new position of each smiley

   For i = 0 To lstSmileys.Size - 1

     Dim Smiley As typSmiley = lstSmileys.Get(i)

     Smiley.X = Smiley.X + Smiley.dX
     Smiley.y = Smiley.y + Smiley.dy
     'change direction
     If Smiley.Y > ((Stage.Height/100)*80) And Smiley.X = (Stage.Width / 100) * 20  Then
       Smiley.Y = ((Stage.Height/100)*80)
       Smiley.dy = -2
       Smiley.dx = 0
     End If
     If Smiley.Y < ((Stage.Height/100)*20) And Smiley.X = (Stage.Width / 100) * 20  Then
       Smiley.Y = ((Stage.Height/100)*20)
       Smiley.dy = 0
       Smiley.dx = 2
     End If
     If Smiley.x > Stage.Width-((Stage.Width/100)*20)  Then
       Smiley.x = Stage.Width-((Stage.Width/100)*20)
       Smiley.dx = 0
       Smiley.dy = 2
     End If
       If  Smiley.X =  Stage.Width-((Stage.Width/100)*20)  Then
         If Smiley.Y =  Stage.Height-((Stage.Height/100)*20)  Then
           Smiley.Y = ((Stage.Height/100)*20)
       Smiley.dy = 0
       Smiley.dx = -2
           End If
     End If
     If Smiley.Y < ((Stage.Height/100)*20)  Then
       Smiley.Y = ((Stage.Height/100)*20)
       Smiley.dy = 0
       Smiley.dx = -2
     End If
     If Smiley.x < ((Stage.Width/100)*20)  Then
       Smiley.x = ((Stage.Width/100)*20)
       Smiley.dx = 0
       Smiley.dy = 2
     End If
End Sub

End Sub

Any help is much appreciated and sorry for probably English mistakes :D