Closed creek23 closed 5 years ago
Never mind, found the logic error in my code. Sharing the snippet for others to reuse.
float referenceX, referenceY; @Override public void onTouchEvent(SmartGLView smartGLView, TouchHelperEvent event) { if (event.getType() == TouchHelperEvent.TouchEventType.SINGLETOUCH) { referenceX = event.getX(event.getNbFingers()-1); referenceY = event.getY(event.getNbFingers()-1); } else if (event.getType() == TouchHelperEvent.TouchEventType.SINGLEMOVE) { int newX = event.getX(event.getNbFingers()-1) - referenceX; int newY = event.getY(event.getNbFingers()-1) - referenceY; Sprite mSprite = renderPassSprite.getRenderObjects().get(i) instanceof Sprite ? ((Sprite) (renderPassSprite.getRenderObjects().get(i))) : null; if (mSprite != null) { mSprite.setPos(mSprite.getPosX() + newX, mSprite.getPosY() + newY); } referenceX = event.getX(event.getNbFingers()-1); referenceY = event.getY(event.getNbFingers()-1); } }
~creek23
from onTouchEvent, I can check for event.getType() for the 3 sequence:
With those 3 events, I'm trying to:
Using the X,Y from above, I apply it to a sprite to give the illusion of Drag-and-Drop, but the sprite moves around like crazy. Am I using Touch Events properly?
~creek23