2017-11-11 130 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)批处理将被窃听。

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

我仍然打开回答为什么会发生此错误。