1

I am in trouble setting the color of my rect. The color of my rect is grey with 0.5f alpha or black with 0. How could I set my color?

This is the code :

Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

shapeRenderer.setColor(67 ,   34 , 167, 0.5f);

shapeRenderer.rect(0, 0, Width, Height);

shapeRenderer.end();
user4789408
  • 1,196
  • 3
  • 14
  • 31
  • 4
    Color values are normalized (between 0 and 1). Assuming you want to specify values between 0 and 255, then divide them by `255f`. (e.g. `setColor(67/255f, 34/255f, 167/255f, .5f)`) – Xoppa May 18 '15 at 17:48

1 Answers1

3

@Xoppa is right

the r, g, b and a in shapeRenderer.setColor(r, g, b, a); are always supposed to be between 0 and 1.

In your case it would be shapeRenderer.setColor(67/255f, 34/255f, 167/255f, 0.5f); And don't forget to add the f behind the numbers because we need float not double.

Fish
  • 1,689
  • 1
  • 18
  • 28