I am looking for detect touch in an actor. The touch in my game is detected in wrong part of the screen. I want to detect touch only on the red circle, here is the code:
Static_values
public class Static_values {
static public float Width = Gdx.graphics.getWidth();
static public float Height = Gdx.graphics.getHeight();
}
Circle class:
public class Circle_Obj extends Actor{
private Vector2 position;
private float radius;
private float speedX;
private float speedY;
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;
speedX = 5.5f;
speedY = 5.5f;
circle = new com.badlogic.gdx.math.Circle(x,y,radius);
texture = new Texture(Gdx.files.internal("texture.png"));
this.setSize(Static_values.Width,Static_values.Height);
this.setPosition(position.x,position.y);
this.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) {
this.setSize(Static_values.Width,Static_values.Height);
this.setPosition(position.x,position.y);
batch.draw(texture, position.x, position.y, radius, radius);
}
Screen class :
public class GameScreen implements Screen {
private Stage stage;
private Circle_Obj circle_obj;
public GameScreen() {
circle_obj = new Circle_Obj(Static_values.Width/3, Static_values.Height/3, Static_values.Width / 100 * 10);
stage = new Stage();
stage.addActor(circle_obj);
Gdx.input.setInputProcessor(stage);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}
/** other methods **/
Colored area = area where touch is detected :