I\'m developing a game using libGDX and I would like to know how I can drag and drop an Actor. I\'ve made my stage and drawn the actor, but I don\'t know how to trigger that eve
In your main gamescreen class add a multiplexer so you can access events from different classes:
private InputMultiplexer inputMultiplexer = new InputMultiplexer(this);
After the gamescreen constructor add as an example:
inputMultiplexer = new InputMultiplexer(this);
inputMultiplexer.addProcessor(1, renderer3d.controller3d);
inputMultiplexer.addProcessor(2, renderer.controller2d);
inputMultiplexer.addProcessor(3, renderer3d.stage);
Gdx.input.setInputProcessor(inputMultiplexer);
In your class that is using the actors use a DragListener as and example:
Actor.addListener((new DragListener() {
public void touchDragged (InputEvent event, float x, float y, int pointer) {
// example code below for origin and position
Actor.setOrigin(Gdx.input.getX(), Gdx.input.getY());
Actor.setPosition(x, y);
System.out.println("touchdragged" + x + ", " + y);
}
}));