我有一个平铺地图和一个动画。但是,地图涵盖了这一点,我不知道为什么。如果我只添加动画,我可以看到它,但是如果我也添加了地图。请回答我,我找不到解决方案!
这是我的代码:
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();
}
}
答案 0 :(得分:1)
在TiledMapRenderer
的顶部渲染动画,以更改渲染顺序。
@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();
}