Android Tutorial Introduction to the libGDX library

Informatix

Expert
Licensed User
Longtime User
The complete changelog is in the first post of the libGDX thread.
 

Carcas

Member
Licensed User
Longtime User
Hello everyone,

how can I add an event to a cell in a hexagonal map?
I want that the hexagons are clickable.

There is no event on the cell !!! (I read the documentation)
You can not add buttons ...
There are no references to the position (X, Y) of the cell on the screen

How did you solve?

Thx Yu
 

JEG

Member
Licensed User
Longtime User
The following works for polygons
1 Get the x/y values from GD_Tap
2 Find the bounding rectangle containing the x/y value
3 If x/y falls in more than one bounding rectangle then
4 For each bounding rectangle get the vertices (v) for the polygon then

Dim comtri As lgMathEarClippingTriangulator
Dim PnP As lgMathIntersector
Dim LSA As lgShortArray

LSA=comtri.computeTriangles(v)
For k = 0 To (LSA.Size-3) Step 3
p1 = LSA.get(k)*2
p2 = LSA.get(k + 1)*2
p3 = LSA.get(k + 2)*2
If PnP.isPointInTriangle(Tx1,Ty1,v(p1),v(p1+1),v(p2),v(p2+1),v(p3),v(p3+1))Then

this is the required polygon
 

Informatix

Expert
Licensed User
Longtime User
You can do something simpler because you don't really need accuracy for a touch. You can use a grid with rectangular cells to detect the touched hexagon:
And the code has to take into account the camera position and zoom factor. Here's the solution that I use in my game:
B4X:
Sub GD_TouchDown(X As Float, Y As Float, Pointer As Int) As Boolean
    'Gets the hex coordinates
Log(" --- ")
Log("Screen: " & X & " , " & Y)
    Dim invY As Float = lGdx.Graphics.Height - Y
    Dim OffsetCameraX As Float = (Camera.ViewportWidth / 2) - (Camera.Position.X / Camera.Zoom)
    Dim OffsetCameraY As Float = (Camera.ViewportHeight / 2) - (Camera.Position.Y / Camera.Zoom)
    Dim relX As Float = X - OffsetCameraX
    Dim relY As Float = invY - OffsetCameraY
Log("Relative to camera: " & relX & " , " & relY)
    Dim HexCoordX As Float = Floor((relX - (OffsetX / Camera.Zoom)) / (HexW / Camera.Zoom))
    Dim ScaledHexH As Float = HexHeight / Camera.Zoom
    Dim HexCoordY As Float = Floor(relY / ScaledHexH)
    If HexCoordX Mod 2 = 0 Then
        HexCoordY = Floor((relY - (ScaledHexH / 2)) / ScaledHexH)
    End If
Log("Hex: " & HexCoordX & " , " & HexCoordY)
    Return False
End Sub
 

Attachments

  • Hexagon.zip
    13.9 KB · Views: 375
Last edited:

eurojam

Well-Known Member
Licensed User
Longtime User

are there any solutions on that problem? I 'am trying the same thing, bringing a rendered shape with libgdx on a panel with a camera preview.
 

wonder

Expert
Licensed User
Longtime User
Hello again,

As you know, I'm starting to take my first steps in Box2D.
There are many excellent tutorials about Box2D on Internet (those of iforce2d for example), so I don’t think it’s useful to cover again this topic. The differences with the original version in C++ are not fundamentals.

Regarding iforce2d, just quick question, is it possible in LibGDX, to import the files generated with their R.U.B.E. Box2D world editor?
 

wonder

Expert
Licensed User
Longtime User

Good morning, Fred.

If you have time, could you elaborate on this matter?
What's the difference between the two?

I'm just curious, if you're having a busy day, leave it for another time.
 

Informatix

Expert
Licensed User
Longtime User
Good morning, Fred.

If you have time, could you elaborate on this matter?
What's the difference between the two?

I'm just curious, if you're having a busy day, leave it.
In Java, there are classes with a constructor without arguments and classes without this constructor (i.e. all constructors require arguments). B4A cannot "dim" the second type to create a new instance. So if you try to create an instance of lgGraphics, you will fail. It's not an object that has to be created by the user. The instance of lgGraphics is created by the library when you call Initialize. To use this object, you have to do Dim Graphics As lgGraphics = lGdx.Graphics. You store in Graphics the reference of the created instance returned by lGdx.Graphics (you could also use directly lGdx.Graphics).
 

Informatix

Expert
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
this is not simple at all
try already for 3 hours to simulate the buoyancy effect but can't get it to work.
the body is just bouncing up and down, it never stop and float on the water.
 

ilan

Expert
Licensed User
Longtime User
this is what i managed to accomplish: (i could not get the part how to calculate the intersection of the two bodies )


the circles are jumping above the water, i could fix that by drawing the water sprite with circle.radius above the water top.
but this is not the real solution.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…