I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View
. I had a android.graphics.Path
in which I stored the coordinates of the user's current touch. In the onDraw()
method of the view I drew the path to the android.graphics.Canvas
. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap
which also was drawn in the onDraw()
method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap
that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth()
. I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer
for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render()
. As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap()
. Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
I'm not very happy with this solution, but it kinda works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With