我正在制作一个简单的 RTS 游戏。我为地图和 UI 创建了单独的阶段,并为侧面板使用了 scene2D 表类。问题是,当我将侧面板悬停时,如果此时面板下方有一个演员(建筑物),它会触发其鼠标悬停事件。点击事件正常工作。
这是我的建筑类输入侦听器:
public class Building extends Actor {
addListener(new InputListener(){
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Click");
return true;
}
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor){
((Building)event.getTarget()).hover = true;
}
这是我的面板类听众
public class SidePanel extends Table {
panelBg = new Image(skin,"side-panel");
addListener(new InputListener(){
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Click");
return true;
}
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor){
System.out.println("Enter");
}
});
addActor(panelBg);
}
}
然后将侧面板添加到 UI 类阶段:
public class UI {
public UI(){
stage = new Stage();
sidePanel = new SidePanel();
stage.addActor(sidePanel);
Gdx.input.setInputProcessor(stage);
}
最后我将 UI 添加到主类:
@Override
public void create () {
ui = new UI();
CP =new InputMultiplexer();
CP.addProcessor(ui.stage);
CP.addProcessor(gameStage);
Gdx.input.setInputProcessor(CP);
}
不确定问题出在哪里,因为单击事件可以正常工作;