如何使用TextButtonStyle.overFont?
How to use TextButtonStyle.overFont?
我正在尝试在 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") ;
}
})
虽然正确考虑了向下和向上状态,但未使用 over 属性:当鼠标进入按钮区域时按钮不会改变。
buttonStyle.fontOverColor = Color.BLUE;
适合我,
尝试传递给您的 TextButton 构造函数而不是皮肤,而是 buttonStyle,
在 TextButton 中有这样的构造函数
public TextButton (String text, TextButtonStyle style)
很难说别的,因为代码看起来不像真正的工作代码,我的意思是 var
关键字或此代码不正确(没有 public 变量 x、y、宽度, 身高):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
如果更改构造函数对您没有帮助,请post您的真实代码。
我正在尝试在 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") ;
}
})
虽然正确考虑了向下和向上状态,但未使用 over 属性:当鼠标进入按钮区域时按钮不会改变。
buttonStyle.fontOverColor = Color.BLUE;
适合我,
尝试传递给您的 TextButton 构造函数而不是皮肤,而是 buttonStyle,
在 TextButton 中有这样的构造函数
public TextButton (String text, TextButtonStyle style)
很难说别的,因为代码看起来不像真正的工作代码,我的意思是 var
关键字或此代码不正确(没有 public 变量 x、y、宽度, 身高):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
如果更改构造函数对您没有帮助,请post您的真实代码。