Reputation: 984
I am a bit confused about touch handling of libGDX. I have seen the usage of all three types.
InputProcessor: http://www.gamefromscratch.com/post/2013/10/24/LibGDX-Tutorial-5-Handling-Input-Touch-and-gestures.aspx
public class InputDemo2 implements ApplicationListener, InputProcessor {
@Override
public void create() {
Gdx.input.setInputProcessor(this);
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
}
}
InputListener
here:
http://www.gamefromscratch.com/post/2013/11/27/LibGDX-Tutorial-9-Scene2D-Part-1.aspx
public MyActor(){
setBounds(actorX,actorY,texture.getWidth(),texture.getHeight());
addListener(new InputListener(){
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
((MyActor)event.getTarget()).started = true;
return true;
}
});
}
InputAdapter
here:
LibGdx, How to handle touch event?
public class Prac1 extends ApplicationAdapter {
@Override
public void create () {
Gdx.input.setInputProcessor(new InputAdapter(){
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return true;
}
});
}
}
I don't find one different from another. Which one should I use?
Upvotes: 2
Views: 2463
Reputation: 20140
InputListener
InputListener
is an EventListener
for low-level input events that is provided for receiving and handling InputEvents.
EventListener
is an interface with a handle(Event)
method that are added to actors to be notified about events. Classes that implement the EventListener
interface use instanceof to determine whether they should handle the event.
An actor just needs to add an InputListener
to start receiving input events.
InputProcessor
An InputProcessor
is used to receive input events from the keyboard and the touch screen (mouse on the desktop). For this it has to be registered with the Input.setInputProcessor(InputProcessor)
method. It will be called each frame before the call to ApplicationListener.render()
.
InputAdapter
InputAdapter
is just an adapter class for InputProcessor
. If you want to override only some methods that you're interested in, use this class.
Upvotes: 5