I was following the solution from this http://stackoverflow.com/questions/20180063/box2d-body-with-texture. I ended up getting this working for static bodies. But when trying to get the PolygonSprite to follow the body it is working but the textures scrolls as the body moves. I would like it to have a set texture and the UV’s don’t change. So, once set the body and texture moves together but the actual region of the texture doesn’t change.
As you can see by the top moving body the texture moves with the body but, the sprite is not staying constant. Every time draw is called the following is done. It recalculates the vertices.
vertices = ActorUtil.calculateVertices(getShape(), body);
short triangles[] = new EarClippingTriangulator().computeTriangles(vertices).toArray();
region = new PolygonRegion(textureRegion, vertices, triangles);
sprite = new PolygonSprite(region);
polyBatch.begin();
sprite.draw(polyBatch);
polyBatch.end();
ActorUtil.calculateVertices
public static float[] calculateVertices(PolygonShape shape, Body body) {
int vertexCount = shape.getVertexCount();
Vector2 mTmp = new Vector2();
float[] vertices = new float[vertexCount * 2];
for (int k = 0; k < vertexCount; k++) {
shape.getVertex(k, mTmp);
mTmp.rotate(body.getAngle() * MathUtils.radiansToDegrees);
mTmp.add(body.getPosition());
vertices[k * 2] = mTmp.x * GameInfo.CONVERSION;
vertices[k * 2 + 1] = mTmp.y * GameInfo.CONVERSION;
}
return vertices;
}