如何在停止前测试旋转量?

时间:2013-03-06 19:16:14

标签: android sprite libgdx

我有一个旋转的精灵,当释放触摸输入时,它会快速旋转回0度。如何在释放触摸输入之前获得精灵的旋转(度数或其他)?

我看起来并且找不到任何方法来实现,谷歌的难题。

编辑对不起,潜在的回复。到目前为止,这是我的代码,我是否可以使用rPower变量来指导抛射物?还没到那么远。

@Override
    public boolean touchDown(int x, int y, int pointer, int button) {

        if (Gdx.input.isTouched(0)) {
        cam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
        }
        if (Gdx.input.isTouched(1)) {
            cam.unproject(touchPoint2.set(Gdx.input.getX(), Gdx.input.getY(), 0));
        }
    return true;
    }


    @Override
    public boolean touchDragged(int x, int y, int pointer) {

    if (Gdx.input.isTouched(0)) {
        cam.unproject(dragPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
        dx = touchPoint.x - dragPoint.x;
        dy = touchPoint.y - dragPoint.y;
        throwerLowerArmSprite.setRotation(dx * 30);
    }
    if (Gdx.input.isTouched(1)){
        cam.unproject(dragPoint2.set(Gdx.input.getX(), Gdx.input.getY(), 0));
        d1x = dragPoint2.x - touchPoint2.x;
        d1y = dragPoint2.y - touchPoint2.y;
        throwerUpperArmSprite.setRotation(d1x * 30);

    }
    return true;
    }

    @Override
    public boolean touchUp(int x, int y, int pointer, int button) {
        if (!Gdx.input.isTouched(0)) {
        cam.unproject(releasePoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
        rPower = releasePoint.x - touchPoint.x;
        throwerLowerArmSprite.setRotation(0);
        }
        if (!Gdx.input.isTouched(1)) {
            cam.unproject(releasePoint2.set(Gdx.input.getX(), Gdx.input.getY(), 0));
            rPower = releasePoint2.x - touchPoint2.x;
            throwerUpperArmSprite.setRotation(0);
            }
        return true;
        }

1 个答案:

答案 0 :(得分:0)

由于touchUp方法中的精灵,你的精灵旋转回0度:

throwerLowerArmSprite.setRotation(0);

所有使用setRotation方法的对象也have a getRoatation() method。因此,您可以使用以下方法保存当前轮换:

float oldRotation = mySprite.getRotation();

与此问题无关,但您可以简化所有输入事件回调。您正在混合事件轮询方法来查找事件回调已经提供的数据。例如,您的touchDown方法可以使用如下参数:

public boolean touchDown(int x, int y, int pointer, int button) {
    if (pointer == 0) {
       cam.unproject(touchPoint.set(x, y, 0));
    } else if (pointer == 1) {
       cam.unproject(touchPoint2.set(x, y, 0));
    }
    return true;
}

这在touchUp方法中更有用,其中pointer参数会告诉您Gdx.input.isTouched不能(即哪个指针不再触及屏幕)。