Android Question [SOLVED] LibGDX - Interactive tiled map within a stage

Discussion in 'Android Questions' started by Jeffrey Cameron, Mar 19, 2015.

  1. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    I've looked at the example program that shows you how to create a tiled map and then pinch/zoom/pan which uses the entire display area for the map. What I'd like to know, is how to create that same behavior while containing the map within a portion of the stage rather than occupying the entire stage, something like:
    Code:
    +==============================+
    |  Main Stage                  |
    |  +------------------------+  |
    |  |  Tiled 
    map display     |  | 
    |  |                        |  |
    |  +------------------------+  |
    |  [random widget]             |
    |  [another widget]            |
    |                              |
    +==============================+
    How can you keep the main stage camera's view fixed and its widgets accessible while changing viewport/zoom on the map? I've tried various combinations of stages and cameras/maprenderers to no avail. This seems like a rather common idea so I hope the answer is a simple one.

    Thanks in advance,
    - Richard
     
  2. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    I've created a demo program that creates a stage, adds group and a text-button and then attempts to render a tiled map inside the group box using its own camera. You can pan as well as zoom the map but its definitely not working as intended.

    If someone with more LibGDX knowledge than I posses (which, granted, isn't very much) can look at it and tell me where I went wrong, or how to modify it to constrain the rendered map to just the group box I would be very grateful.

    Thanks in advance,

    Richard
     

    Attached Files:

  3. Informatix

    Informatix Expert Licensed User

    Did you try ClipBegin and ClipEnd of your group ? These functions limit the drawing to the area of your group. You have to call Begin before drawing, and End at the end, as usual.

    Try also the scissors (look at the Scissors example).
     
    Jeffrey Cameron likes this.
  4. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Thank you, Informatix, I'll investigate those both!
     
  5. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    You were spot-on, Informatix, I was attempting to make it too complex. The ClipBegin and ClipEnd methods did the trick!

    I've attached the completed example that displays the tiled map within a group and lets you pan/zoom the map within that area. It is fairly heavily documented to explain what is going on.

    I've also included a bonus routine that will center the map's camera on the requested table cell and position it in the center of the group viewing area.

    Thanks once again for pointing me in the correct direction!
     

    Attached Files:

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