How do I set background color in libgdx? -
I am trying to make the background a sky blue with RGB of 135,2206,235. When I run it, the background is not expected.
Public Zero Render () {Gdx.gl.glClearColor (.135f, .206f, .235f, 1); Gdx.gl.glClear (GL20.GL_COLOR_BUFFER_BIT); Batch.begin (); Batch.rara (img, 0, 0); Batch.end (); }
glClearColor
uses range from 0 to 1 Therefore, you need to continually split by 255 F and map from the 0 - 255 range:
Gdx.gl.glClearColor (135 / 255f, 206/255f, 235/255f , 1);
Be careful when dividing 2 integers, if you do not convert any float (or double), the integer division will be used and the result is 0 (255/255 = = 1)
Comments
Post a Comment