Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 平滑地改变图像的位置_Java_Libgdx - Fatal编程技术网

Java 平滑地改变图像的位置

Java 平滑地改变图像的位置,java,libgdx,Java,Libgdx,我是这样实现的 但是我的主要问题是,如果我在屏幕上拖动图片,图片就无法顺利更改。 我画的像这样的状态是我怎样才能检测到向左或向右移动 int before=state-1; if(before>-1) batcher.draw(text.get(before), 16,200, 64, 64); batcher.draw(text.get(state), 96, 200,128, 128); int after=state+1;

我是这样实现的 但是我的主要问题是,如果我在屏幕上拖动图片,图片就无法顺利更改。 我画的像这样的状态是我怎样才能检测到向左或向右移动

    int before=state-1;
    if(before>-1)
        batcher.draw(text.get(before), 16,200, 64, 64);

    batcher.draw(text.get(state), 96, 200,128, 128);

    int after=state+1;
    if(after<3)
        batcher.draw(text.get(after), 240, 200, 64, 64);

    batcher.draw(Assets.arrow,320, 32, -64, 64);
    batcher.end();

删除C++标签,因为<代码>公共类X扩展了y<代码>当然不是C++,我不是C++,你的管理员添加了这个:)我在javajava:Admin中编程,我认为这是一个脚本,因为你忘记了自己的标签。无论如何,我现在添加了java标记。
public class SimpleDirectionGestureDetector extends GestureDetector {
    public interface DirectionListener {
        void onLeft();

        void onRight();

        void onUp();

        void onDown();
    }

    public SimpleDirectionGestureDetector(DirectionListener directionListener) {
        super(new DirectionGestureListener(directionListener));
    }

    private static class DirectionGestureListener extends GestureAdapter{
        DirectionListener directionListener;

        public DirectionGestureListener(DirectionListener directionListener){
            this.directionListener = directionListener;
        }

        @Override
        public boolean fling(float velocityX, float velocityY, int button) {
            if(Math.abs(velocityX)>Math.abs(velocityY)){
                if(velocityX>0){
                    directionListener.onRight();
                }else{
                    directionListener.onLeft();
                }
            }else{
                if(velocityY>0){
                    directionListener.onDown();
                }else{                                  
                    directionListener.onUp();
                }
            }
            return super.fling(velocityX, velocityY, button);
        }

    }
}