Java Libgdx旋转图像按钮
我正在尝试将图像按钮旋转90度。当我调用Java Libgdx旋转图像按钮,java,android,libgdx,scene2d,Java,Android,Libgdx,Scene2d,我正在尝试将图像按钮旋转90度。当我调用按钮。setRotation(90)时,它会旋转按钮,但不会旋转与按钮关联的图像。我知道实际的按钮是旋转的,因为当它被点击时,我打印出true,并且它感觉到按钮应该旋转90度的点击。但是,设置按钮的位置会同时移动按钮和图像。如何确保图像随按钮旋转?谢谢大家! package com.davejones.test; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx
按钮。setRotation(90)
时,它会旋转按钮,但不会旋转与按钮关联的图像。我知道实际的按钮是旋转的,因为当它被点击时,我打印出true,并且它感觉到按钮应该旋转90度的点击。但是,设置按钮的位置会同时移动按钮和图像。如何确保图像随按钮旋转?谢谢大家!
package com.davejones.test;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
public class Test extends ApplicationAdapter {
Stage stage;
ImageButton button;
ImageButton.ImageButtonStyle imageButtonStyle;
BitmapFont font;
Skin skin;
TextureAtlas textureAtlas;
ExtendViewport viewport;
@Override
public void create () {
stage = new Stage();
skin = new Skin();
viewport = new ExtendViewport(64,48);
viewport.getCamera().position.set(32, 24, 0);
textureAtlas = new TextureAtlas("image.pack");
skin.addRegions(textureAtlas);
Gdx.input.setInputProcessor(stage);
font = new BitmapFont();
imageButtonStyle = new ImageButton.ImageButtonStyle();
imageButtonStyle.imageUp = skin.getDrawable("image");
button = new ImageButton(imageButtonStyle);
button.setPosition(100, 100);
button.setRotation(90);
stage.addActor(button);
}
@Override
public void render () {
System.out.println(button.isPressed());
super.render();
stage.draw();
}
@Override
public void dispose () {
stage.dispose();
skin.dispose();
font.dispose();
textureAtlas.dispose();
}
}您需要将按钮的transfrom设置为true:
...
button.setTransform(true);
button.setRotation(90);
...
发件人:
公共空集合变换(布尔变换)
如果为true(默认值),
该批处理将被转换,以便在其父批处理中绘制子批
坐标系。这对性能有影响,因为Batch.flush()
必须在转换之前和之后执行。如果一组演员
如果不旋转或缩放,则可以设置组的变换
这是错误的。在这种情况下,每个子对象的位置将由
组的绘图位置,使子对象显示在
即使批次尚未转换,位置也正确
因此,如果您在transform设置为true的情况下绘制了许多组,请注意可能的性能影响。不确定这是否有帮助。如果为true(默认值)。。。。正如您所看到的,默认情况下它是真的。它是针对Group类的。对于ImageButton,默认情况下为false可能重复