Reputation: 1299
I am using libGDX on Android. I set up the Stage and added a CustomActor with a custom draw. It's working properly. However, I am not able to get any logs for the touchDragged method via the InputListener for this actor. Even the code within it does not run.
Here is the required exposure to the code:
public class CustomActor extends Actor {
public CustomActor() {
this.setListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
//This log doesn't print up!
Gdx.app.log("CustomActor","touchDragged");
//This code doesn't work either
Vector2 v = CustomActor.this.localToParentCoordinates(new Vector2(x,y));
CustomActor.this.setPosition(v.x, v.y);
}
});
}
}
Can anyone help me out here on what am I missing ?
Upvotes: 0
Views: 269
Reputation: 3675
public boolean addListener (EventListener listener) {...}method of Actor. Which version of libgdx are you using? I think actor does not have "setListener" method.
Upvotes: 0
Reputation: 6231
Add the Stage
you are using as InputProcessor
to receive the events else the Stage
can't forward the event to the actors.
Gdx.input.setInputProcessor(stage);
Should do it.
Upvotes: 1