LibGdx-Batch未绘制最后一个.draw命令

LibGdx-Batch未绘制最后一个.draw命令,libgdx,Libgdx,所以这很奇怪。。。 我有一个抽象的基本屏幕。此屏幕初始化show()上的SpriteBatch()。init()调用BaseScreen的一个抽象方法。 此绘制问题来自使用“gameView”视口,该视口是ExtendViewport SpriteBatch batch; @Override public void show(){ batch = new SpriteBatch(); gameView = new ExtendViewport(SV.V_WIDTH, SV.V_H

所以这很奇怪。。。 我有一个抽象的基本屏幕。此屏幕初始化show()上的SpriteBatch()。init()调用BaseScreen的一个抽象方法。 此绘制问题来自使用“gameView”视口,该视口是ExtendViewport

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。我使用它们来设置批次的投影矩阵

draw(batch,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);
}
现在,这段代码绘制如下:

注意它如何不绘制文本

以下是仅batch.draw的结果-(省略font.draw)

现在问题变成了“上次调用的是哪种类型的.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);
}
将吸引

还有这个

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);
}
将吸引

这是一个有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);
}

还有最后一件事。。。最后一批抽签。。。如果您尝试在0处绘制,则会发生这种情况

寻求任何有用的反馈和/或可能发生这种情况的原因。我是LibGdx的新手,不会回避您对我决定如何使用此框架的反馈


非常感谢

所以我缩小了引起它的原因: 当你在工作时,这批人似乎不会被窃听

1) 在基类上实例化批处理 2) 在基类呈现方法上调用batch.start 3) 在batch.start之后调用基类中的一个抽象方法 4) 这批货将被窃听

我解决这个问题的方法是将批处理代码移到派生类中,一切正常


我仍然愿意回答为什么会发生此错误。

要打印窗口,请按Alt+PrintScreen,或者只使用屏幕截图工具,如剪贴工具。这样就不会留下那样难看的伤口