2016-07-09 68 views
0

你好:)在LibGDXLibGDX:無法管理渲染TiledMap類與視口

最近我已經開始編程。現在即時通訊4天停留在視口上呈現TiledMap。我無法弄清楚,但我知道這是可能的。下面是測試TiledMap類的樣子:

Testing tiled map

如何現在的遊戲看起來(無牌顯示):

The PlayScreen now (No tiles showing) Screen is blue becouse of ClearColor code down below.

這裏是我的播放屏幕代碼:

public class PlayScreen implements Screen, InputProcessor{ 
    MainGame game; 

    private OrthographicCamera camera; 
    private Viewport gamePort; 

    private OrthogonalTiledMapRenderer renderer; 


    public PlayScreen(MainGame game) { 
     this.game = game; 

     camera = new OrthographicCamera(); 
     gamePort = new StretchViewport(MainGame.V_WIDTH/MainGame.PPM, 
       MainGame.V_HEIGHT/MainGame.PPM, camera); 
     renderer = new OrthogonalTiledMapRenderer(LevelManager.tiledMap, 
       1/ MainGame.PPM); 
     camera.position.set(gamePort.getWorldWidth()/2, gamePort.getWorldHeight()/2, 0); 

     Gdx.input.setInputProcessor(this); 
    } 

    @Override 
    public void show() { 

    } 

    public void update(float delta){ 
     camera.update(); 
    } 

    @Override 
    public void render(float delta) { 
     update(delta); 

     Gdx.gl.glClearColor((float)66/255, (float)66/255, (float)255/255, 0f); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

     renderer.setView(camera); 
     renderer.render(); 
    } 

    @Override 
    public void resize(int width, int height) { 
     gamePort.update(width, height); 
    } 

    @Override 
    public void pause() { 

    } 

    @Override 
    public void resume() { 

    } 

    @Override 
    public void hide() { 

    } 

    @Override 
    public void dispose() { 

    } 

    @Override 
    public boolean keyDown(int keycode) { 
     return false; 
    } 

    @Override 
    public boolean keyUp(int keycode) { 
     return false; 
    } 

    @Override 
    public boolean keyTyped(char character) { 
     return false; 
    } 

    @Override 
    public boolean touchDown(int screenX, int screenY, int pointer, int button) { 
     return false; 
    } 

    @Override 
    public boolean touchUp(int screenX, int screenY, int pointer, int button) { 
     return false; 
    } 

    @Override 
    public boolean touchDragged(int screenX, int screenY, int pointer) { 
     return false; 
    } 

    @Override 
    public boolean mouseMoved(int screenX, int screenY) { 
     return false; 
    } 

    @Override 
    public boolean scrolled(int amount) { 
     return false; 
    } 
} 

LevelManager.tiledMap被加載到MainGame類的create方法中,所以我加載它就好了,但它不顯示屏幕上。它當我不使用視口時。

謝謝大家對未來的幫助:)

+0

如果MainGame中的常量是整數,則將它們轉換爲在視口構造函數中浮動。 – Tenfour04

回答

0

我發現用問題出來了,這是becouse PPM(每米像素)MainGame類,已在格式整數,它必須是浮動否則地圖將不會呈現縮放問題。