Reputation: 1371
I have a tiled map and an animation. However, the map covers this last and I don't know why. If I add only the animation, I can see it, but not if also I add the map. Please answer me, I can't find the solution!
Here is my code:
public class MyGdxGame extends ApplicationAdapter implements GestureDetector.GestureListener
{
Texture texture;
SpriteBatch batch;
Sprite sprite;
TextureAtlas textureAtlas;
Animation animation;
float time;
OrthographicCamera orthographicCamera;
Texture corridore;
Sprite spriteCorridore;
TiledMap map;
OrthogonalTiledMapRenderer renderer;
@Override
public void create () {
batch = new SpriteBatch();
corridore = new Texture("a.png");
spriteCorridore = new Sprite(corridore);
orthographicCamera = new OrthographicCamera(500,500);
orthographicCamera.position.x=500;
orthographicCamera.position.y=250;
map = new TmxMapLoader().load("mappa.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
textureAtlas = new TextureAtlas(Gdx.files.internal("corsa.atlas"));
animation = new Animation(1/20f,textureAtlas.findRegion("a"),textureAtlas.findRegion("b"),
textureAtlas.findRegion("c"),textureAtlas.findRegion("d"),textureAtlas.findRegion("e"),
textureAtlas.findRegion("f"),textureAtlas.findRegion("g"),textureAtlas.findRegion("h"),
textureAtlas.findRegion("i"));
}
@Override
public void render () {
time = time + Gdx.graphics.getDeltaTime();
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(orthographicCamera.combined);
batch.begin();
batch.draw((TextureRegion)animation.getKeyFrame(time,true),orthographicCamera.position.x-spriteCorridore.getWidth()/2,orthographicCamera.position.y-spriteCorridore.getHeight()/2);
renderer.setView(orthographicCamera);
renderer.render();
orthographicCamera.translate(1, 0);
orthographicCamera.update();
batch.end();
}
}
Upvotes: 0
Views: 41
Reputation: 20140
Render your animation at the top of TiledMapRenderer
so change your rendering order.
@Override
public void render () {
time = time + Gdx.graphics.getDeltaTime();
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setView(orthographicCamera);
renderer.render();
batch.setProjectionMatrix(orthographicCamera.combined);
batch.begin();
batch.draw((TextureRegion)animation.getKeyFrame(time,true),orthographicCamera.position.x-spriteCorridore.getWidth()/2,orthographicCamera.position.y-spriteCorridore.getHeight()/2);
batch.end();
orthographicCamera.translate(1, 0);
orthographicCamera.update();
}
Upvotes: 1