Android Question Libgdx: how to generate an event for Map_Exagonal

Discussion in 'Android Questions' started by Carcas, Mar 23, 2015.

  1. Carcas

    Carcas Member Licensed User

    Hello everyone,

    I created an hexagonal map as the example "Map_Hexagonal". (Libgdx example by Infomatrix)

    I want to know how to add a "click" event to every single cell

    or some other way to get the same result.

    Thank You
     
  2. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Look at Informatix's "Map tIDE" example in his example suite to see how to set up the lgGestureDector and apply that to your app. Then, in the GD_Touchdown event you can translate the touch to your grid co-ordinates using your Stage.ScreenToStageCoordinates method. Something like:
    Code:
    Sub GD_TouchDown(X AsFloat, Y AsFloat, Pointer AsInt) As Boolean
         
    Dim poVect As lgMathVector2

         
    ' calculate where we touched
         poVect.X = X
         poVect.Y = Y
         poVect = MainStage.ScreenToStageCoordinates(poVect)
         
    Dim piX As Int = FromPixelToTile_X(poVect.X)
         
    Dim piY As Int = FromPixelToTile_Y(poVect.Y)
         LogColor(
    "GD TOUCH Map Pos: " & piX & ", " & piY, Colors.Magenta)

         
    Return False
    End Sub
    If you are unfamiliar with the "FromPixel..." methods please see Informatix's PacDroid example.
     
  3. Carcas

    Carcas Member Licensed User

  4. Carcas

    Carcas Member Licensed User

    Code:
    Sub GD_TouchDown(X AsFloat, Y AsFloat, Pointer AsInt) As BooleanDim poVect AslgMathVector2
    ' calculate where we touched poVect.X = X
    poVect.Y = Y
    poVect = MainStage.ScreenToStageCoordinates(poVect)
    Dim piX As Int = FromPixelToTile_X(poVect.X)Dim piY As Int = FromPixelToTile_Y(poVect.Y)
    LogColor(
    "GD TOUCH Map Pos: " & piX & ", " & piY, Colors.Magenta)
    ReturnFalseEnd 
    Sub

    does not exist in "Map_tIDE" example

    ?!?

    ps: you must have an stage ??
     
  5. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Correct, but it does have a gesture detector and it shows you how to initialize it. You can add additional events for the detector to handle touches (this example) or panning, zooming, etc.

    I'm not sure if a stage is required, I just use one to make things easier as it has its own viewport, spritebatch and camera objects.
     
    Last edited: Mar 24, 2015
  6. Carcas

    Carcas Member Licensed User

    What is 'MainStage' in your project?

    Code:
    Dim piX As Int = FromPixelToTile_X(poVect.X)
    Dim piY As Int = FromPixelToTile_Y(poVect.Y)
    FromPixelToTile give error. The compiler does not recognize it

    Jefrey could you post the complete and running code?
    I can not understand :(
     
  7. Informatix

    Informatix Expert Licensed User

    There's a complete solution in the libGDX tutorial thread.
     
  8. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    MainStage is just a lgScn2DStage object. As for the "FromPixel..." methods, I already told you to take a look at Informatix's PacDroid example (click the word "PacDorid" in post #2). His PacDroid tutorial has a perfect example of those methods and he explains them very well too, if I recall correctly.

    Giving any type of "complete and running code" for LibGDX is usually very problematic due to how the interface works. You really are much better off going through the examples Informatix has created and then combining the parts you need from his various example programs. To understand the examples, take the time to read through his LibGDX Tutorial it really does a good job of explaining the fundamentals.

    Now, knowing which items you need to use when, that I am afraid I am still discovering myself ;)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice