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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -