libGDX:ClickListener 延迟
libGDX: Delay in ClickListener
我想在单击此按钮时更改按钮样式。
这是我的解决方案:
show(){
...
Gdx.input.setInputProcessor(stage);
stage.add(myButton);
}
public void render(float delta){
final boolean buttonSwitch;
myButton.addListener(new ClickListener() {
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
if(buttonSwitch == true)
{
myButton.setStyle(style1);
}
else
{
myButton.setStyle(style2);
}
}
});
}
问题是有时我的点击会被忽略,样式不会改变。我必须点击三次或更多次才能获得结果。
在渲染方法中添加监听器??为什么 !!
从 render 方法中删除以下代码片段并保留在 show()
方法中
final boolean buttonSwitch;
myButton.addListener(new ClickListener() {
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
myButton.setStyle(buttonSwitch?style1:style2);
buttonSwitch=!buttonSwitch;
}
});
我想在单击此按钮时更改按钮样式。 这是我的解决方案:
show(){
...
Gdx.input.setInputProcessor(stage);
stage.add(myButton);
}
public void render(float delta){
final boolean buttonSwitch;
myButton.addListener(new ClickListener() {
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
if(buttonSwitch == true)
{
myButton.setStyle(style1);
}
else
{
myButton.setStyle(style2);
}
}
});
}
问题是有时我的点击会被忽略,样式不会改变。我必须点击三次或更多次才能获得结果。
在渲染方法中添加监听器??为什么 !!
从 render 方法中删除以下代码片段并保留在 show()
方法中
final boolean buttonSwitch;
myButton.addListener(new ClickListener() {
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
myButton.setStyle(buttonSwitch?style1:style2);
buttonSwitch=!buttonSwitch;
}
});