【发布时间】:2015-07-21 05:33:35
【问题描述】:
我正在寻找触摸检测。下面显示的代码是我在我的应用程序中设置圆圈的方法。我想检测这个圆圈上的触摸,而不是整个纹理周围或整个纹理。奇怪的是没有检测到触摸,我无法检测到它 圈子类:
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);
}
}
屏幕类:
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 **/
}
【问题讨论】:
-
你试过“stage = new Stage();