[SOLVED] Transparent TextureRegion Draw

Anything libgdx related goes here!

[SOLVED] Transparent TextureRegion Draw

Postby Redkin » Wed Aug 14, 2019 5:46 pm

When i try to draw a region
Code: Select all
 spriteBatch.draw(region, sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight());

The region is drawn transparent!
But when i use a sprite that dont happens, this is the first time this issue happened to me, someone knows what is going on?
Last edited by Redkin on Wed Aug 14, 2019 7:48 pm, edited 1 time in total.
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm

Re: Transparent TextureRegion Draw

Postby shatterblast » Wed Aug 14, 2019 6:15 pm

SpriteBatch just sets up an order of things to draw, like a significantly fancier version of Java's Queue. If you have not already, you should attach your SpriteBatch to a Stage. Also, you should add your Actors to Stage, not SpriteBatch. Otherwise, a SpriteBatch carrying no references to any Drawable objects will do nothing.

If you only have a few Actors, I think you could call draw() on the Actors themselves, which you probably lack here, but I highly suggest using Stage for that as well.

While you do not indicate using Scene2D, the code in the following section should still help:
https://github.com/libgdx/libgdx/wiki/Scene2d#viewport
shatterblast
 
Posts: 368
Joined: Sun Jul 06, 2014 1:14 pm

Re: Transparent TextureRegion Draw

Postby tomski » Wed Aug 14, 2019 6:45 pm

You shouldnt just use Stage and scene2d graph. There are time and place to do so, and I would typically recommend you do not use Stage and scene2d for your gameplay objects.

If you have tinted your SpriteBatch with an alpha, then it might become transparent. How have you determined that its transparent? If its that you cant see it, then perhaps your positiion and sizes arent right.
tomski
 
Posts: 897
Joined: Wed Jun 26, 2013 6:06 pm

Re: Transparent TextureRegion Draw

Postby Redkin » Wed Aug 14, 2019 7:39 pm

I use this to clear the screen, the alpha is set to 1,
i dont know why the texture regions are transparent (like if the image alpha was 0.5), if i use a sprite that dont happen! :(
Code: Select all
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT| GL20.GL_DEPTH_CLEAR_VALUE);
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm

Re: Transparent TextureRegion Draw

Postby Redkin » Wed Aug 14, 2019 7:42 pm

I didnt tinted my spritebatch at all:

Code: Select all
 batch.setProjectionMatrix(cam.combined);
        batch.begin();
        grassbg2.sprite.draw(batch);
        grassbg1.sprite.draw(batch);
        mapache.draw(batch);
        batch.end();
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm

Re: Transparent TextureRegion Draw

Postby Redkin » Wed Aug 14, 2019 7:48 pm

Lol found a solution!

Code: Select all
 batch.setColor(1,1,1,1);


This never happened to me before, maybe some things changed in libgdx, but with that code it works is not transparent anymore, thanks all!
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot] and 1 guest