【问题标题】:Button doesn´t rotate libGDX按钮不旋转 libGDX
【发布时间】:2017-08-10 07:22:06
【问题描述】:

我想旋转一个按钮。于是我写了如下代码:

public void show () {
        skin2 = new Skin (Gdx.files.internal("SettingsButton.json"));
        button2 = new Button(skin2);
        button2.setPosition(25,1440);
        button2.setSize(120,120);
        button2.setOrigin(button2.getWidth() / 2, button2.getHeight() / 2);
        button2.addAction(Actions.repeat(RepeatAction.FOREVER,
                Actions.sequence(
                        Actions.rotateBy(360, 1), 
                        Actions.rotateTo(0))));
        button2.addListener(new ClickListener(){
            @Override
            public void clicked(InputEvent event, float x, float y) {
                game.setScreen(new SettingsScreen(game));
                super.clicked(event, x, y);
            }
        });

        stage.addActor(button2);
}

不幸的是,按钮没有旋转,但我不知道为什么。 如何改进我的代码?

【问题讨论】:

    标签: java android button libgdx rotation


    【解决方案1】:

    出于性能原因,大多数scene2d.ui 组默认将transform 设置为false。

    更多详情可以查看
    https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale

    您需要使用setTransform(..)方法启用转换

    button2.setTransform(true);
    

    【讨论】:

    • 谢谢!是否可以设置旋转速度?
    • 旋转速度是什么意思?
    • 我想设置按钮在特定时间段内转多少圈,例如一分钟转一圈比一分钟转五圈慢。所以我想设置它。
    • Actions.sequence(Actions.rotateBy(360, 1)) 通过此操作在一秒内旋转一圈,如果您希望以秒为单位增加旋转速度,请在 10 秒内旋转一圈 Actions.sequence(Actions.rotateBy(360, 10))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多