我正在尋找觸摸檢測。下面的代碼顯示了我在應用程序中設置了一個圓圈。我想在這個圓圈上檢測觸摸,而不是在整個紋理周圍或整個紋理上。奇怪的是,觸摸檢測不到,在無處我可以檢測到它 Circle類:Libgdx Actor未檢測到觸摸輸入
public class Circle_Obj extends Actor{
private Vector2 position;
private float radius;
private com.badlogic.gdx.math.Circle circle;
private Texture texture;
public Circle_Obj(float x, float y, float radius) {
position = new Vector2(x,y);
this.radius = radius;
circle = new com.badlogic.gdx.math.Circle(x,y,radius);
texture = new Texture(Gdx.files.internal("texture.png"));
addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("TOUCHED", " TOUCHED ");
return true;
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture,0, 0);
}
}
Screen類:
public class GameScreen implements Screen {
private Stage stage;
private Circle_Obj circle_obj;
public GameScreen() {
circle_obj = new Circle_Obj(Static_values.Width/2, Static_values.Height/2, Static_values.Width/100 * 10);
stage = new Stage(new FitViewport(Static_values.Width/3, Static_values.Height/3));
stage.addActor(circle_obj);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}
@Override
public void dispose() {
stage.dispose();
}
/** other methods **/
}
沒有嘗試只是「階段=新階段(); – Fish