我在舞台上添加了一些演员。当我尝试处理Actors tap事件时,pan功能无法正常工作。为什么?怎么做才有效? 这是我的问题的摘要。
Main.java
public class Main extends ApplicationAdapter implements GestureListener{
static Grid grid;
static Stage main_stage;
static InputMultiplexer inputs;
static GestureDetector gdect;
@Override
public void create () {
main_stage = new Stage();
inputs = new InputMultiplexer();
grid = new Grid();
grid.addToStage(main_stage);
inputs.addProcessor(main_stage);
dect = new GestureDetector(this);
inputs.addProcessor(gdect);
Gdx.input.setInputProcessor(inputs);
}
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
System.out.println("pan");
return false;
}
}
Grid.java
public class Grid {
static Fields [] fields;
void addToStage(Stage stage){
for(int i = 0; i < fields.length; i++)
stage.addActor(fields[i]);
}
}
Fields.java
public class Fields extends Actor {
addListener(new ActorGestureListener(){
public void tap(InputEvent event, float x, float y, int count, int button) {
System.out.println("tap");
}
});
}