我有问题或只是不知道如何使它起作用,以便在图像中看到所有内容。
rotation = lerp(rotation, realRotation, delta / 2);
图像gif
您想在特定角度(触摸板设置)与原始(默认)值之间进行线性插值。
我正在尝试在我的代码中达到您的要求。
public class TestGame1 extends Game {
Stage stage;
Touchpad touchpad;
Image image;
float angle=0;
Texture shipTex;
@Override
public void create() {
stage=new Stage();
image=new Image(shipTex=new Texture("ship1.png"));
image.setPosition(300,300);
image.setSize(100,107);
image.setOrigin(50,53);
Skin skin=new Skin(Gdx.files.internal("skin/uiskin.json"));
touchpad=new Touchpad(10,skin);
touchpad.setPosition(100,100);
Gdx.input.setInputProcessor(stage);
stage.addActor(image);
stage.addActor(touchpad);
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0,0,0,1);
stage.act();
stage.draw();
float knobX=touchpad.getKnobPercentX();
float knobY=touchpad.getKnobPercentY();
if(knobX!=0 && knobY!=0) {
float radAngle = MathUtils.atan2(knobY, knobX);
angle = MathUtils.radiansToDegrees * radAngle;
angle -= 90;
if (angle > 360)
angle -= 360;
}
else
angle=MathUtils.lerpAngleDeg(angle,0,Gdx.graphics.getDeltaTime());
image.setRotation(angle);
}
@Override
public void dispose() {
stage.dispose();
shipTex.dispose();
}
}