5
\$\begingroup\$

I'm trying to draw a filled rectangle in Libgdx and according to the API this should work:

shapeRenderer.begin(ShapeRenderer.ShapeType.FilledRectangle);

But it gives me an error and tells me to change FilledRectangle to Filled, Pointor Line.

imports: import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

Any ideas on what is causing this?

\$\endgroup\$
7
\$\begingroup\$

If you read the documentation, you'll see that ShapeRenderer.ShapeType is an enum with the following values defined:

Filled 
Line 
Point 

So the error message you're receiving is accurate.

If you want to draw a filled rectangle, choose the Filled enum type, then use shape rederer to draw a rectangle:

 shapeRenderer.begin(ShapeType.Filled);
 shapeRenderer.identity();
 shapeRenderer.translate(20, 12, 2);
 shapeRenderer.rotate(0, 0, 1, 90);
 shapeRenderer.rect(-width / 2, -height / 2, width, height);
 shapeRenderer.end();
|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

With LibGdx 0.9.8 they removed ShapeyType.Rectangle, ShapeType.FilledRectangle and introduced Filled, Line, Point to optimize the shape rendering.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.