[英]How to properly create a mouse Listener for CheckBox in LibGDX Scene2D?
I've been searching online for hours and I'm new to LibGDX game development. 我已经在网上搜索了几个小时,并且是LibGDX游戏开发的新手。 This link was useful, but I still have not been able make my CheckBox work.
该链接很有用,但是我仍然无法使CheckBox正常工作。 How to properly implement CheckBox in LibGDX
如何在LibGDX中正确实现CheckBox
I'm using LibGDX and I have to implement two Radio buttons in my menu. 我正在使用LibGDX,我必须在菜单中实现两个单选按钮。
I created two CheckBox and assigned them a style. 我创建了两个CheckBox并为其分配了样式。
check_style = new CheckBox.CheckBoxStyle();
check_style.font = font;
check_style.fontColor = new Color(Color.WHITE);
check_style.checkboxOff = check_skin.getDrawable("checkbox");
check_style.checkboxOn = check_skin.getDrawable("checkbox2");
check_style.checked = check_skin.getDrawable("checkbox2");
I also added a listener to notice mouse clicks 我还添加了一个侦听器来注意鼠标的点击
controls1Check.addListener(new InputListener() {
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
controls1Check.toggle();
System.out.println("toggle");
}
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Controls1: " + controls1Check.isChecked());
return true;
};
});
When I run my program it does not respond to any mouse click. 当我运行程序时,它不会响应任何鼠标单击。 How can I resolve this?
我该如何解决?
Thank you! 谢谢!
I guess you are adding your CheckBox
to a Stage
? 我猜您是将
CheckBox
添加到Stage
吗? If so, my only idea is that maybe you didn't call Gdx.input.setInputProcessor(yourStage);
如果是这样,我唯一的想法是也许您没有调用
Gdx.input.setInputProcessor(yourStage);
so even though your CheckBoxes have InputListeners, input is actually not being processed. 因此,即使您的CheckBoxes具有InputListeners,实际上也不在处理输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.