1

I'm a beginner with java and libgdx, and i'm trying to make a simple sprite of a rectangle slowly going out/in of the screen when I swipe (with GestureDetector). Is there any tool with libgdx to do a simple task like that?

Here the code I have without any animation :

private Sprite rect;

private void drawRect(){
//some code to draw the rectangle as a sprite on a SpriteBatch
// (the rectangle's position is a the top right of the screen)
}    

 @Override
public boolean fling(float velocityX, float velocityY, int button) {
    //swipe right to close
    if (velocityX >= 150 && !rectClosed) {
        rect.setPosition(rect.getX() + rectWidth, rect.getY());
        rectClosed = true;
    }
    //swipe left to open
    if (velocityX <= -150 && rectClosed) {
        rect.setPosition(xRectOrigine, rect.getY());
        rectClosed = false;
    }
    return false;
}

Thank you !

Yoann Far
  • 322
  • 4
  • 12
  • You could make some sort of animation. A handy tool in LibGDX for such tasks is the 'Interpolation' class. Read this page for more information about the topic: https://github.com/libgdx/libgdx/wiki/Interpolation – TVASO Apr 05 '19 at 17:02
  • Thank you I think that's exactly what I was looking for ! – Yoann Far Apr 06 '19 at 03:36

0 Answers0