2017-11-11 127 views
1

所以這很奇怪... 我有一個抽象的BaseScreen。這個屏幕在show()上初始化一個SpriteBatch。 init()調用BaseScreen的抽象方法之一。 這場平局問題是使用「gameView」視這是一個ExtendViewportLibGdx - 批處理沒有繪製最後的.draw命令

SpriteBatch batch; 
@Override 
public void show(){ 
    batch = new SpriteBatch(); 
    gameView = new ExtendViewport(SV.V_WIDTH, SV.V_HEIGHT); 
    hudView = new ScreenViewport(); 
    init(); 
} 

這是我在渲染功能做:

@Override 
public void render(float delta){ 
    /* 
     Just in case render is being called more than usual 60 times, 
     I want to call update only 60 times per second. (SV.STEP = 1/60f) 
    */ 
    accum += delta; 
    while(accum >= SV.STEP){ 
     accum -= SV.STEP; 
     update(); 
    } 

    /* Clear Screen */ 
    Gdx.gl.glClearColor(0, 0, 0, 1); 
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    /* DRAW WORLD */ 
    batch.setProjectionMatrix(gameView.getCamera().combined); 
    gameView.apply(true); 
    batch.begin(); 
    draw(batch, SV.BatchType.World); 
    batch.end(); 

    /* DRAW UI 
    batch.setProjectionMatrix(hudView.getCamera().combined); 
    hudView.apply(true); 
    batch.begin(); 
    draw(batch, SV.BatchType.UI); 
    batch.end();*/ 
} 

我有兩個視口,一個遊戲世界和一個爲HUD。我用它們來設置批次的投影矩陣。

平局(批次,SV.BatchType.World)命令最終拍攝代碼到這裏:

private void drawBody(Batch batch){ 
    Vector2 position = body.getPosition(); 
    //Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight()); 
    batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100); 
} 

現在這段代碼繪製這樣的:它 2 Draws

注意如何不畫出文字。

這裏只有batch.draw結果 - (省略font.draw) 1 Draw

現在的問題就變成了「什麼類型的.draw的被稱爲最後的」,它忽略了所有的人 - 例如:

private void drawBody(Batch batch){ 
    Vector2 position = body.getPosition(); 
    //Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight()); 
    batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100); 
    font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100); 
} 

將借鑑

3 consecutive fonts

private void drawBody(Batch batch){ 
    Vector2 position = body.getPosition(); 
    //Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight()); 
    batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100); 
    font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100); 
    batch.draw(heart, position.x,position.y, h_width*2, h_height*2); 
    batch.draw(heart, position.x,position.y+ 100, h_width*2, h_height*2); 
} 

將借鑑

2 batch draw at end

這裏是6平的例子,但你必須有一個 '一次性' 最後.draw

private void drawBody(Batch batch){ 
    Vector2 position = body.getPosition(); 
    //Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight()); 
    batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100); 
    font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100); 
    batch.draw(heart, position.x,position.y, h_width*2, h_height*2); 
    batch.draw(heart, position.x,position.y+ 100, h_width*2, h_height*2); 
    font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100); 
    batch.draw(heart, 10,10, h_width*2, h_height*2); 
} 

6 draws

這是最後一件事......最後一批抽籤......如果你試圖抽籤0,0 - >發生這種情況 position 0 0 draw

尋求任何有用的反饋和/或爲什麼會發生這種情況。我是LibGdx的新手,不會迴避你如何決定使用這個框架的反饋。

非常感謝!

+0

要打印窗口,請按Alt + PrintScreen或只使用截圖工具,如剪切工具。這樣它不會留下這樣的難看的傷口 –

回答

1

所以我縮小是什麼原因造成: 它似乎沒有該批次會當你是

1實例化上呼籲batch.start基類 2)該批次被竊聽) BASE類渲染方法 3)batch.start後調用BASE類中的抽象方法之一 4)批處理將被竊聽。

我解決這個問題的方法是將批處理代碼移入派生類,並且一切正常。

我仍然打開回答爲什麼會發生此錯誤。