I am studying the use of libgdx with the universal tween engine and cannot figure out how to click (or click on a desktop application) a point on the screen and move the texture completely by touching, without supporting the touch or click, until the end point is reached.
When a touch event is triggered, the animation starts and the image moves to its place. The graphic will follow the finger / mouse pointer if you start tapping and dragging. If I touch the point, the graphic will move to the point until the touch key is pressed. Then he stops where he was when pressed.
I look at touch-and-release and get this graphic transition to the affected point, and probably don’t understand anything about the tween engine implementation. I have inserted the swap code below.
public void render() { camera.update(); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(texture.getTexture(), texture.getBoundingBox().x, texture.getBoundingBox().y); batch.end(); Tween.registerAccessor(Plane.class, new TextureAccessor()); TweenManager planeManager = new TweenManager(); float newX = 0; float newY = 0; boolean animateOn = false; if(Gdx.input.isTouched()) { newX = Gdx.input.getX(); newY = Gdx.input.getY(); animateOn = true; } if (animateOn == true && (texture.getX() != newX || texture.getY() != newY)) { Tween.to(texture, TextureAccessor.POSITION_XY, 10) .target(newX, newY) .ease(TweenEquations.easeNone) .start(planeManager); planeManager.update(1); if (texture.getX() == newX && texture.getY() == newY) { animateOn = false; } } }
Initially, I had tweening code inside the conditional expression for isTouched() and did not use newX , newY or animateOn . I thought using isTouched() only to set new coordinates and state of the animation, then the loop will start in the animation. The older code looked like this:
if(Gdx.input.isTouched()) { newX = Gdx.input.getX(); newY = Gdx.input.getY(); Tween.to(texture, TextureAccessor.POSITION_XY, 10) .target(newX, newY) .ease(TweenEquations.easeNone) .start(planeManager); planeManager.update(1); }
I also tried using justTouched() , but the graphics engine only moved slightly towards the affected point.
I struggled with this for several hours, I would really appreciate it if someone could point me in the right direction.
Thanks.