Creating unique bodies by specifying vertices
Not everything in our physics simulations must be made of rectangles or circles. We can also create polygonal bodies by creating a list of the polygonal points. This approach is useful for creating certain types of terrain, vehicles, and characters. In this recipe, we will demonstrate how to create a unique body from a list of vertices.
Getting ready...
Create an activity by following the steps in the Introduction to the Box2D physics extension section given at the beginning of the chapter. This activity will easily allow the creation of a uniquely constructed body with vertices.
How to do it...
Complete the following steps to define and create our unique, polygonal body:
Our unique body's vertices will be defined by a list of
Vector2
objects. Add the following list to theonPopulateScene()
method:List<Vector2> UniqueBodyVertices = new ArrayList<Vector2>(); UniqueBodyVertices.addAll((List<Vector2>) ListUtils.toList( new Vector2...