gpt4 book ai didi

java - Android LibGDX : tiled map covers animation

转载 作者:行者123 更新时间:2023-12-02 12:55:21 26 4
gpt4 key购买 nike

我有一张平铺 map 和一个动画。然而, map 涵盖了最后这一点,我不知道为什么。如果我只添加动画,我可以看到它,但如果我还添加 map ,我就看不到它。请回答我,我找不到解决方案!

这是我的代码:

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();
}

}

最佳答案

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();
}

关于java - Android LibGDX : tiled map covers animation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44442719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com