java - 雪碧不会停止移动(Libgdx)

时间:2015-03-10 23:42:41

标签: java libgdx sprite

我无法阻止精灵移动。

这是我的代码:

boolean moving;

Gdx.input.setInputProcessor(new Input(){
       public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            projected = new Vector3(screenX, screenY,0);
            cam.unproject(projected);

            if(position.x != projected.x || position.y != projected.y){
                pathX = projected.x - position.x;
                pathY = projected.y - position.y;

                distance = (float) Math.sqrt(pathX * pathX + pathY * pathY);
                directionX = pathX / distance;
                directionY = pathY / distance;

                moving= true;
            }
            if(projected.x == position.x || projected.y == position.y){
                moving = false;
            }
            return true;

}

public void render(float delta) {
        Gdx.gl.glClearColor(1,1,1,1);
        Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);   

        if(moving){
            System.out.println(moving);

            position.x += directionX * Speed * delta;
            position.y += directionY * Speed * delta;
        }

移动的问题总是正确的,无论怎样,精灵都不会停止。

0 个答案:

没有答案