2017-09-25 33 views
0

The print from my game的TMX地圖僅呈現兩個街區到屏幕和所有其餘的是黑色

我通過學習YouTube上的教程(https://www.youtube.com/watch?v=P8jgD-V5jG8&t=43s)到像下發展一個supermario遊戲,代碼的作者本教程在他的github上提供了今天仍在工作,但它是遊戲的完整代碼,而且我仍然在視頻課程6中,因爲在這裏他的結果與我的不同(正如您可以從中看到的那樣圖片)。

如果您有任何經驗豐富的開發人員能告訴我我錯在哪裏只顯示2塊tmx地圖,我將不勝感激。我爲我的英語道歉,感謝您的幫助。

的主類遊戲:

public class MarioBros extends Game {

public SpriteBatch batch; 
public static final int V_WIDTH = 400; 
public static final int V_HEIGHT = 208; 


@Override 
public void create() { 
    batch = new SpriteBatch(); 
    setScreen(new PlayScreen(this)); 
} 

@Override 
public void render() { 
    super.render(); //Delega o metodo render para as SCREENS que estão ativas. 
} 

@Override 
public void dispose() { 
    batch.dispose(); 

} 

}

的播放屏幕(我認爲問題就在這裏!):

public class PlayScreen implements Screen { 
private MarioBros game; 
private OrthographicCamera gamecam; 
private Viewport gamePort; 
private HUD hud; 

private TmxMapLoader maploader; 
private TiledMap map; 
private OrthogonalTiledMapRenderer renderer; 


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

    gamecam = new OrthographicCamera(); 
    gamecam.position.set(gamePort.getWorldWidth()/2, gamePort.getWorldHeight()/2, 0); 
    gamePort = new FitViewport(MarioBros.V_WIDTH, MarioBros.V_HEIGHT, gamecam); 
    gamePort.apply(); 

    hud = new HUD(game.batch); 

    // Loading the map we made in Tile 
    maploader = new TmxMapLoader(); 
    map = maploader.load("level1.tmx"); 
    renderer = new OrthogonalTiledMapRenderer(map); 


} 

@Override 
public void show() { 

} 

public void handleInput(float dt) { 
    if (Gdx.input.isTouched()) 
     gamecam.position.x += 100 * dt; 

} 

public void update(float dt) { 
    handleInput(dt); 

    gamecam.update(); 

} 

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

    Gdx.gl.glClearColor(0, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    renderer.render(); 
    game.batch.setProjectionMatrix(hud.stage.getCamera().combined); 
    hud.stage.draw(); 
} 

@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() { 
    renderer.dispose(); 
} 

}

的鐵漢:

public class HUD implements Disposable{ 
public Stage stage; 
private Viewport viewport; // Novo viewport 
private Integer worldTimer; 
private float timeCount; 
private Integer score; 

Label countdownLabel; // Label é equivalente ao widget, nessa biblioteca gdx 
Label scoreLabel; 
Label timeLabel; 
Label levelLabel; 
Label worldLabel; 
Label marioLabel; 

public HUD(SpriteBatch sb){ 
    worldTimer = 300; 
    timeCount = 0; 
    score = 0; 

    viewport = new FitViewport(MarioBros.V_WIDTH, MarioBros.V_HEIGHT, new OrthographicCamera()); 
    stage = new Stage(viewport, sb); // Stage é um bloco que você insere coisas (inicialmente soltas dentro dele) 

    Table table = new Table(); // Prender os itens em uma tabela 
    table.top(); // Coloca no topo do nosso stage 
    table.setFillParent(true); // largura do nosso stage 

    countdownLabel = new Label(String.format("%03d", worldTimer), new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 
    scoreLabel = new Label(String.format("%06d", score), new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 
    timeLabel = new Label("TIME", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 
    levelLabel =new Label("1-1", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 
    worldLabel =new Label("WORLD", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 
    marioLabel =new Label("MARIO", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); 

    //expandX vai expandir X ao maximo, por isso devemos por em todos para eles dividirem igualmente o eixo X. 
    table.add(marioLabel).expandX().padTop(10); 
    table.add(worldLabel).expandX().padTop(10); 
    table.add(timeLabel).expandX().padTop(10); 
    table.row(); 
    table.add(scoreLabel).expandX(); 
    table.add(levelLabel).expandX(); 
    table.add(countdownLabel).expandX(); 

    //inserir a table no estagio 
    stage.addActor(table); 

} 

@Override 
public void dispose() { 
    stage.dispose(); 
} 

}

感謝您抽出時間來盡力幫助我,我已經失去了整整一個星期試圖解決這個問題= /(SAD)

+0

你確定你的tmx文件是正確的嗎?這兩個區塊是顯示在其左下角還是其他地方?我對libgdx瞭解不多,因此我可能會圍繞'gamecam.position.set(gamePort.getWorldWidth()/ 2,gamePort.getWorldHeight()/ 2,0)來玩遊戲。 gamePort = new FitViewport(MarioBros.V_WIDTH,MarioBros.V_HEIGHT,gamecam);' – Kilazur

+0

謝謝你試圖幫助!是的,我使用的是本教程的作者正在使用的同一個tmx文件,他的工作正常。 –

回答

0

只是比較你與this類的所有教程的源代碼。

+0

我已經做了,但他仍然不需要完整的代碼來使場景出現,這就是我想要做的,但感謝您的建議。 –

+0

@RananMariani嘗試複製你已經寫過的片段。有時它對我來說工作得很好。 – icarumbas