我是使用Java和libgdx的初学者,我正在尝试制作一个简单的矩形精灵,当我滑动(使用GestureDetector)时,它会慢慢从屏幕中移出/移入矩形。 libgdx是否有任何工具可以执行类似这样的简单任务?
这是我没有任何动画的代码:
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;
}
谢谢!