How to draw custom shapes using simple texture in libgdx?

I want to draw custom static shapes in my game, just like angry birds: angry birds

but the problem is that the texture is square.

static ground

how can we say "spritebatch" to draw shapes with some vertices? Does anyone have any ideas?

+6
source share
1 answer

According to docs :

SpriteBatch is used to draw 2D rectangles that reference a texture (region)

Thus, this method does not allow you to specify any other geometry than the rectangle. However, there is a draw method that allows you to specify the four coordinates of the "rectangle" and turn them into something else. You must decompose the geometry into smaller pieces corresponding to these primitives. It seems that this method is not amenable to changes in geometry.

You better create a grid and just draw it. The mesh does not support triangulation, so use the ObjLoader.loadObj * methods to load the mesh into the Alias ​​Wavefront OBJ . Specifying geometry should not be a problem; The article refers to some sample files.

+4
source

Source: https://habr.com/ru/post/915481/


All Articles