按钮不会旋转libGDX

问题描述:

我想旋转一个按钮。所以我写了下面的代码:按钮不会旋转libGDX

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); 
} 

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

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

更多细节,您可以检查
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale

您需要使用setTransform(..)方法

button2.setTransform(true); 
+0

谢谢您启用变换!有没有设置旋转速度的可能性? – user8340536

+0

你是什么意思的旋转速度? – Aryan

+0

我想设置按钮在某段时间内的旋转次数,例如一分钟内的一次革命比一分钟内的五次革命更慢。所以我想设置它。 – user8340536