silverFoxA
silverFoxA

Reputation: 4659

Drawing app for android using libGDX

I am new to the libGdx framework but i have been developing android apps for couple months now. The problem that i'm facing is that i'm unable to get a way to make an app where i can draw the items as user make using gestures. I have searched a lot but couldn't find a work around to do the following using libgdx framework.

Basically what my plan is:

  1. I will check if the user is dragging "isdragging()", if yes i want to use either "DDA algorithm" to create the lines as per the inputs received from the "dragstart()" from the "Gesturedetection" interface but i'm not receiving any data from the methods.

  2. based on the user's action the pixmap will be rendered.

Any sort of help will be helpful.

Upvotes: 1

Views: 547

Answers (1)

m.antkowicz
m.antkowicz

Reputation: 13571

assuming you are using Scene2D you can easily use DragListener binded with your stage to get (x,y) pointer position whenewer user will touch down the stage and move his pointer

stage.addListener( 
    new DragListener()
    {
        public void drag(InputEvent event, float x, float y, int pointer)
        {
            Vector2 v = new Vector2(x, y);
            positionArray.add(v); //positionArray is Array<Vector2> type in this example
        }
    }
);

then you can just remember the position in an Array for example (Array seems to be nice choose) and in the render part you can use ShapeRenderer or some another tool to render these points. Because you have all points remembered you can easily remove them when using "rubber".

Regards, Michał

Upvotes: 1

Related Questions