I am developing an application using multi-touch in AndEngine. To get the coordinates of touching fingers I use pSceneTouchEvent.getMotionEvent().getX([pointer index])
because TouchEvent doesn't have an equivalent getter, only pSceneTouchEvent.getX()
.
The problem is that MotionEvent returns coordinates on the screen while TouchEvent returns coordinates on the Scene. When I zoom in or out, the screen and Scene coordinates do not match, so I need to convert the screen coordinates to Scene coordinates. How can I do that?
Solution found. Andengine handles touch events in a different way to Android so there is no history of touch coordinates. I simply store them myself in private variables before handling the event:
if (pSceneTouchEvent.getPointerID() == 0) {
pointer0LastX = pSceneTouchEvent.getX();
pointer0LastY = pSceneTouchEvent.getY();
}
if (pSceneTouchEvent.getPointerID() == 1) {
pointer1LastX = pSceneTouchEvent.getX();
pointer1LastY = pSceneTouchEvent.getY();
}
Then I just access these instead of getting the values from the TouchEvent.