Touch Events co-ords inverted…

I’ve just checked out the latest build, and it seems there have been some changes to android input handling. I hadn’t previously updated for a few months, and my older version did not have this issue.

A click in the lower left corner now seems to register as a click in the upper right, and vice versa.

I found these lines:
[java]
/**
* Flip X axis
*/
protected boolean mouseEventsInvertX = true;

/**
 * Flip Y axis
 */
protected boolean mouseEventsInvertY = true;[/java]

in AdroidHarness.java

yet toggling the value to false and rebuilding has apparently no effect at all. I still have the same issue. Any ideas?

Are you using the onTouch event to get the touch coordinates or the mouseButton/Motion events?

The mouseEventsInvert methods are only applied to the case where the touch events are converted into simulated mouse events which using the onMouseButtonEvent and onMouseMotionEvents in inputManager. The onTouch event uses the following to generate the position:

[java]
case MotionEvent.ACTION_DOWN:
touch = getNextFreeTouchEvent();
touch.set(Type.DOWN, event.getX(pointerIndex), view.getHeight() - event.getY(pointerIndex), 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
processEvent(touch);

[/java]

I was using touch events, but this is only part of the problem. The issue also applies to clicking on NiftyGui elements - and I do not handle those events in my code at all (nifty does). These are still inverted.
So what is the right course or action here? I’d prefer not to be using an outdated android lib…

How are the coordinates? If 0/0 is bottom left its correct and you should change your game code and not the engine code.

0/0 is bottom left for the PC build - but top right on android.

I can change the code to handle the non-nifty clicks - but what can I do so that the co-ords are correct for the nifty elements?

@iwgeric Is there any reason for this?

I’m checking this now. Nifty used to work just fine on Android, at least related to mouse click location.

@jon81, a test case with a very simple nifty screen would help me a lot. I don’t have any nifty projects right now.

The coordinates that are used on Android depend on 3 settings in AndroidHarness (which can be changed in the user MainActivity.java file)

[java]
/**
* If true MouseEvents are generated from TouchEvents
*/
protected boolean mouseEventsEnabled = true;

/**
 * Flip X axis
 */
protected boolean mouseEventsInvertX = true;

/**
 * Flip Y axis
 */
protected boolean mouseEventsInvertY = true;

[/java]

If mouseEventsEnabled is set true (default), then jME’s Android input system will take a touch event from Android and convert it into a mouse button event. The x and y value for the mouse button event are modified based the mouseEventInvertX and mouseEventInvertY settings. When mouseEventsEnabled is true, Nifty uses the simulated mouse event and the modified x and y values instead of the raw onTouch event with the original x and y values.

When I print the x and y values of the onTouch event, the bottom-left corner of the screen is 0,0 just like the mouse event on the PC.

When I print the x and y values of the mouse button event with the settings above at the defaults (all set true), the onTouch event x and y values are still 0,0 at the bottom-left corner, but the onMouseButton event x and y values are 0,0 at the top-right corner. However, changing the mouseEventInvertX and mouseEventInvertY to false, the onMouseButton event changes to be 0,0 at the bottom-left corner.

Since Nifty’s origin is the top-left corner, jME internally inverts the y value before sending it to Nifty. This is done for the mouseButton event for PC as well as the simulated mouseButton event and touch event for Android.

I really need a test case with a Nifty screen to check further, but the code that sends the x and y values to Nifty looks like it is sending the correct x and y values.

If you can’t send a test case that shows the problem, try setting mouseEventsEnabled = false in MainActivity.java to see if it changes anything.

@iwgeric

thanks, setting mouseEventsEnabled = false and using touch events has resolved the issue.

It really should have worked with mouseEventsEnabled = true as well. When I get a chance I’ll create a nifty test case and check.