2017-11-11 7 views
1

これはかなり変です... 私は抽象的なBaseScreenを持っています。この画面は、show()のSpriteBatchを初期化します。 init()は、BaseScreenの抽象メソッドの1つを呼び出します。 このドロー問題は、これは私がレンダリング機能で何をすべきかですExtendViewportLibGdx - バッチは最後の.drawコマンドを描画していません。

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

は「gameView」ビューポートを使用してから、次のとおりです。

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

私は2つのビューポート、ゲームの世界のための1つを持っています1つは鼻のためです。私はそれらを使用してバッチの投影行列を設定します。

ドロー(バッチ、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が描くと例ですが、 '使い捨て' を持っている必要があり、最後の

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

を.drawここに一つの最後のことがあります...最後のバッチドロー...あなたがそれを描こうとするならば0、0 - >これが発生します position 0 0 draw

これが起こっている可能性がありますフィードバックをお手伝いしてください。私はLibGdxの初心者で、このフレームワークをどのように使用するかについてのあなたのフィードバックを払わないでしょう。

ありがとうございました!

+0

ウィンドウを印刷するには、Alt + PrintScreenを押すか、スナップツールなどのスクリーンショットツールを使用します。そうすれば、それはそのような醜いカットを残さないでしょう –

答えて

1

だから私はそれを引き起こしているものを絞り込む: あなたが

1のときバッチが盗聴されることを思われない)BASEクラス 2上のバッチをインスタンス化)にbatch.startを呼び出しますBASEクラスのレンダリングメソッド 3)BASEクラスの抽象メソッドの1つをbatch.startの後に呼び出します。 4)バッチが盗聴されます。

私がこの問題を解決するために行ったのは、バッチコードを派生クラスに移動することでしたが、すべて正常に動作します。

このバグがなぜ発生するのかについてはまだ解明されています。

関連する問題