how to draw custom shapes using a simple texture in libgdx?

霸气de小男生 提交于 2020-01-01 03:15:06

问题


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

but the problem is that the texture is in square shape.

how we can tell to the "SpriteBatch" to draw shapes with some vertices? does anybody has some ideas?


回答1:


According to the docs:

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

So essentially, this method does not allow you to specify any other geometry than a rectangle. However, there is a draw method that allows you to specify the four coordinates of the "rectangle" and turn it into something else. You'd've to decompose the geometry into smaller pieces that fits this primitives. Looks like this method doesn't lend itself to geometry changes.

Better you create a mesh and just draw it. The mesh does not support triangulation, so use the ObjLoader.loadObj* methods to load a mesh in Alias Wavefront OBJ format. Specifying the geometry shouldn't be a hassle; the article links to some example files.



来源:https://stackoverflow.com/questions/10547897/how-to-draw-custom-shapes-using-a-simple-texture-in-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!