Reputation: 73
I am new to Libgdx and am doing a game prototype with a certain features. One of which I am unable to achieve at the moment is to darken the map such that my character can "glow" in the dark map.
Before Blending Output:
Currently, I load my map using TiledMap
and TiledMapRenderer
.
Load my map:
TiledMap map = new TmxMapLoader().load("map/ascent/ascent.tmx");
float unitScale = 2f;
OrthogonalTiledMapRenderer tiledMapRenderer = new OrthogonalTiledMapRenderer(map, unitScale);
In my render()
method:
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Run the playMovement Method
player1Movement(playerHashMap.get(p1), delta);
// Draw the Map
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
// Set the brightness and blend function
float lightness = .1f;
Gdx.gl.glClearColor(lightness,lightness,lightness,1f);
tiledMapRenderer.getBatch().enableBlending();
tiledMapRenderer.getBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
// Begin Batch drawing
tiledMapRenderer.getBatch().begin();
// Draw the light
tiledMapRenderer.getBatch().draw(light, p1.box.x - 25f, p1.box.y - 25f, 80, 80);
// Draw the player
playerHashMap.forEach((player, input) -> player.draw(tiledMapRenderer.getBatch()));
tiledMapRenderer.getBatch().end();
}
My attempt at blending:
I tried blending and is unable to darken my surroundings map.
Qn: Is there any way to darken a TiledMap?
I would like to thank you all in advance for your advice for your help !
Upvotes: 1
Views: 347
Reputation: 711
You can get the batch that renders the map and apply a tint before drawing. The tint would darken by reducing all the RGB values (or lightening etc).
final float darken =0.5f;
tiledMapRenderer.getBatch().setColor(darken,darken,darken,1f);
and then you don't need to set the clear color and blend.
Yes, setColor
should be called setTint
!!
Upvotes: 2