我试图在TextButton上使用overFont
和overColor
,以便鼠标移动时按钮外观会发生变化。
这是我定义的风格。
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
按钮创建如下:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
在正确考虑向下和向上状态的同时,不使用过度属性:当鼠标进入按钮区域时按钮不会改变。
答案 0 :(得分:1)
buttonStyle.fontOverColor = Color.BLUE;
对我来说很好,
尝试传递给TextButton构造函数而不是skin,但是buttonStyle,
在TextButton中有这样的构造函数
public TextButton (String text, TextButtonStyle style)
很难说别的,因为代码看起来不像真正的工作代码,我的意思是var
关键字或者此代码不正确(没有公共变量x,y,width,height ):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
如果更改构造函数对您没有帮助,请发布您的真实代码。