2017-06-08 86 views
0

我有一個平鋪地圖和動畫。但是,地圖覆蓋了這最後,我不知道爲什麼。如果我只添加動畫,我可以看到它,但如果我也添加了地圖,則不會。請回答我,我找不到解決方案!Android LibGDX:平鋪地圖封面動畫

這裏是我的代碼:

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

} 

回答

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

Yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeessssssssssssssssssssssssssssssssssssssss !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! – Curio