2012-06-30 34 views
6

He utilizado el dibujo de textura para 2 imágenes, pero la imagen de fondo se vuelve negra. La imagen de origen es png y es transparente. ¿Cómo puedo solucionar esto?libgdx texture image transparent render

¿Cómo visualizo la imagen original con transparencia?

Respuesta

1

Pruebe spritebatch.enableBlending() si lo ha deshabilitado antes. Debe ser habilitado por defecto sin embargo.

29

Prueba esto:

  spriteBatch.begin(); 
      //background 
      seaTexture = new Texture(px); 
      Color c = spriteBatch.getColor(); 
      spriteBatch.setColor(c.r, c.g, c.b, 1f); //set alpha to 1 
      spriteBatch.draw(seaTexture, 0, 0, 480, 320); 
      //foreground 
      c = spriteBatch.getColor(); 
      spriteBatch.setColor(c.r, c.g, c.b, .3f);//set alpha to 0.3 
      spriteBatch.draw(blockTexture, 50, 100, 120, 120); 

      spriteBatch.end(); 
+0

que necesitaba para borrar la pantalla en primer lugar con esta línea 'Gdx.gl.glClear (GL20.GL_COLOR_BUFFER_BIT);' 'antes spriteBatch.begin()' para ver los efectos alfa por [instrucciones aquí] (https://github.com/libgdx/libgdx/wiki/Spritebatch,-Textureregions,- y-Sprites) – rockhammer

+1

Por supuesto, debe hacer esto. Acabo de mostrar la parte más importante del código. – Nolesh