0

回転するスプライトがあり、タッチ入力を離すとすぐに 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;
        }
4

1 に答える 1

0

touchUpメソッドの次の理由により、スプライトは 0 度に戻ります。

throwerLowerArmSprite.setRotation(0);

メソッドを持つすべてのオブジェクトには、メソッドsetRotationありますgetRoatation()。したがって、現在の回転を次の方法で保存できます。

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示すメソッドでさらに便利です。pointerGdx.input.isTouched

于 2013-03-13T16:29:41.143 に答える