Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to drag and drop actors on libgdx scene2d?

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 event.

Please try to help me using my own architecture.

public class MyGame implements ApplicationListener 
{
    Stage stage;
    Texture texture;
    Image actor;

    @Override
    public void create() 
    {       
        texture = new Texture(Gdx.files.internal("actor.png"));
        Gdx.input.setInputProcessor(stage);
        stage = new Stage(512f,512f,true);

        actor = new Image(texture);
        stage.addActor(actor);
    }

    @Override
    public void render() 
    {       
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        stage.draw();
    }
}
like image 838
Juan Mitchell Avatar asked Apr 29 '13 20:04

Juan Mitchell


People also ask

How do I move an actor in Libgdx?

For moving an actor to a specific location you can use MoveToAction. With this you can set the final location and also how long it it takes to move to that location.


1 Answers

Take a look at the Example in the libgdx examples. Here is the drag and drop test from the libgdx test classes: DragAndDropTest

If you just want to drag/slide your Actor around you need to add a GestureListener to it and pass your Stage to the Inputprocessor like this:Gdx.input.setInputProcessor(stage);. Here is the GestureDetectorTest from libgdx. For drag events its the Flinglistener.

like image 152
BennX Avatar answered Oct 06 '22 14:10

BennX