Draw a curved user object in LIBGDX?

What i need

I recently studied LibGDX and it seems to hit the wall seen in the picture, the blue dot represents the user's finger, map generation is where I seem to be stuck, does LibGDX a way to dynamically draw curved objects? I could just generate them on my own as images, but then the image is very stretched to the point of the gap for the finger, it can fit 3! But it also needs to be 1000 PX tall to fit the design of the entire level.

Is it such that I have to draw hundreds of polygons side by side to make a curved line? On the side, I don’t need a way to determine when an object has a bottom up, so I can create another β€œpiece” of the map.

+8
java android line curve libgdx
source share
2 answers

You do not need hundreds of polygons to make the curve as you painted. You can get away with 40 quads on the left and 40 quads on the right, and it will look pretty smooth. Raise this to 100 on each side and it will look almost perfectly smooth, and no modern device will have problems working at 60 frames per second.

You can use the Mesh class to create a procedural grid for each side. You can make the grid in one place locked by the camera and change its vertices and UVs so that they look like you are panning an infinitely long corridor. It will take quite a bit of math in front, but should be smooth if you have it.

Basically, your level design can be based on some equation that takes Y offset as input. Or it can be a long array of offsets, and you can use a spline equation or a linear equation to interpolate between them. The result will be the UV and X coordinates, which can be used to update each of the vertices of your two grids.

You can use the vertex shader to effectively update the UV coordinates using a constant constant offset parameter that you update every frame. Thus, you do not need to transfer UV data to the GPU in each frame.

For vertex positions, use your Mesh, the underlying float[] , and call setVertices() each frame to update it. Info here .


Actually, it might look better if you leave only the UV and X positions and just scroll the Y positions up. Save a couple of squares of the pad on top and bottom of the screen and simply move the top square to the bottom after scrolling the screen.

+1
source share

How to create a set of curved shapes that can be combined together. As the gap in the middle will be above and below each image in the middle (with the same curvature at the end and at the beginning of the point) ... And between the start and end points you can go crazy in shape.

And finally, you can randomly place these images and get an endless world.

If you do not want to stop in the middle each time, you can also have three entry and exit points (left, middle, right) ... and after the image that ends to the left, you certainly need to add an image that starts from the left, but can end somewhere else ...

0
source share

All Articles