Textures aren't rendering properly

Anything libgdx related goes here!

Textures aren't rendering properly

Postby samxcr » Mon May 13, 2019 1:04 am

I implemented a basic lighting system (https://stackoverflow.com/questions/45595319/transparent-circle-black-around/45598754#45598754) to my game and now some of my textures won't render. Here's my main render method:
Code: Select all
public void render(float delta) {



Gdx.gl.glClearColor(CLEAR, CLEAR, CLEAR, 1);

batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE);

// render lights



batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

// render map and its entities (including player)
currentMap.render(camera, batch);


batch.setBlendFunction(GL20.GL_ZERO, GL20.GL_SRC_COLOR);
batch.draw(frameBuffer.getColorBufferTexture(), -1, 1, 2, -2);

When I run the game, the light is rendered and the TiledMap from the currentMap object is rendered, however my other entities such as the player and buildings are not. The currentMap.render() method looks like this:
Code: Select all

for(Entity e : entities) {

// render player LAST

I'm guessing it is something to do with the SpriteBatch being set up incorrectly as the player and entities use the batch and don't render while the TiledMap doesn't use it and does render.

To try and figure it out I created a basic Sprite and rendered it by calling batch.draw(sprite, 0, 0); just before my currentMap.render() line, but that is just rendered as a white rectangle.

What would be causing this?
Code: Select all
Posts: 10
Joined: Mon May 13, 2019 1:02 am

Re: Textures aren't rendering properly

Postby shatterblast » Mon May 13, 2019 3:52 am

I am just taking a guess, but make sure they are all in the same SpriteBatch? Like... make sure that everything fits between batch.begin() and batch.end() while only having ONE of each? While it is okay to have more than one SpriteBatch, containing your stuff to just a single full stretch is important for troubleshooting. This is just something I do, but if I have different stretches of SpriteBatch objects, I give them different variable names. Otherwise, it gives an opportunity for something to be over-written and lost that you might have wanted when you begin() and end() multiple times with some single lonely SpriteBatch that wonders, "What the heck is going on?" In other words, your render() method should only contain batch.begin() and batch.end() once.
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Return to Libgdx

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest