Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

LibGdx: Mismatch between mouse position and selected tile(world position)

Alright, I was able to find a solution on my own, since the problem was rather in the logic and not in the LibGdx API. In case somebody else has the same issue in the future, I'll provide the solution here.

At first I followed Angel-Angel's tip and started to move the camera instead of the map/world. Second, the main problem was the fact, that I used the screen coordinates of my mouse/finger for the tile highlighting, instead of the world coordinates.

The new code:

    //scrolling routine
    if (Gdx.input.isTouched()) {
        //get mouse/finger position in screen
coordinates and save in a Vector3
Gdx.input.getY(), 0);

        //get the distance moved by mouse/finger
since last frame and translate camera to that
        //(I have no idea yet why the x-axis is
        deltaX = (float)Gdx.input.getDeltaX();
        deltaY = (float)Gdx.input.getDeltaY();
        camera.translate(-deltaX, deltaY, 0);

        //this is the solution, the coordinates
that you use for tile highlighting
        //are translated to world coordinates
        touchPos = camera.unproject(touchPos);

    //update the camera position and the math that
is involved


    //now the highlighting routine is working with
world coordinates, touchPos.y,
game.batch, world);

I hope this will help out in the future. If anyone is interested how I get the right tile for highlighting, I use the method described in the highest rated answer in this thread:

Hexagonal Grids, how do you find which hexagon a point is in?

Good luck and have fun!

Categories : Android

Related to : LibGdx: Mismatch between mouse position and selected tile(world position)
How can one append a div exactly in the position where the mouse is over? jQuery
You will need to use mousemoves() to get the event data and coordinate like below $( "#target" ).mousemove(function( event ) { var msg = "Handler for .mousemove() called at "; msg += event.pageX + ", " + event.pageY; console.log(msg); }); and you will need a div with css {position:absolute; width:10px; height:10px; background-color:yellow; left: event.pageX; top:event.pageY} somethi

Categories : Javascript
how to return position of spinner so that the selected option can be selected again
As per document, Spinner's onItemSelected Callback method to be invoked when an item in this view has been selected. This callback is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.

Categories : Android
CSS z-index: "position: relative;" element on top of "position: fixed;" element - It will not work
You have to set z-index to container .dashboard-header. .dashboard-header { z-index: 2; } Fiddle:

Categories : HTML
DOM element position slow while scrolling + difference between scrollbar-scrolling and mouse/touchpad-scrolling
I had the exact same issue, and it took me some time to figure out the fix. Here is an updated jsfiddle showing you how to resolve the issue in Safari: function handle_scroll() { $("#slide").css({ '-webkit-transform': 'translate3d(' + $("#container").scrollLeft() + 'px, 0, 0)' }); var leftPos = 0; for(var i = 0; i < 1900 ; i++) { leftPos = $("#s

Categories : Javascript
How can I get Position from ArrayList<>
Add one more String field page in Item class : public class Item { private String text; private Bitmap image; private String page; public Item(Bitmap image,String text,String page){ this.image = image; this.text = text; = page; } public Bitmap getImage() { return image; } public String getText() { return text;

Categories : Java
Recently Add
Wait for all requests in Android Volley
android scrollview not working
Android: How to prevent a Wifi disconnect on DHCP renewal?
Using HorizontalScrollView for gallery - no pictures inside
-bash: export: not a valid identifier
m3u8 Video stops with MediaPlayer: Error (1,-1004)
java.lang.IndexOutOfBoundsException at ListView android
Facebook REST calls for mobile cross-platform app
How to returning image from camera intent and placing in google maps api v2 as thumbnail
How can I add a row to a ListView in one Fragment by clicking the button in another Fragment?
Using MediaController on Android 5
Is TCP packet filtering possible on mobile platforms?
Spinner from editext android
Incomplete file downloaded in android using DataInputStream
How do I delete a row form SQLite DB via ListView and refresh list view?
Change action bar to toolbar, and now I am having force closes. What am I doing wrong here?
Adding buttons below GraphView, all inside a Fragment
Get rotation and display in degrees
What methods are available to execute things in the background
Data Persistence Android
Intent not delivered correctly
Android Studio 1.0 RC 1 Gradle build issues - Could not run build action using Gradle installation
otto eventbus for android behaves differently in release build
How get item ID from ListFragment in android?
Receive bluetooth connection changes after reboot
Encrypting plain-text passwords and passing variables to xml for display in android
android html5 video fullscreenchange not called on entering fullscreen
Want to create API for my android application done using Intel XDK
Gps not getting location
Spannable Text is not working in Dialog Fragment
© Copyright 2017 Publishing Limited. All rights reserved.