所以这很奇怪......我有一个抽象的BaseScreen . 此屏幕在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'而忽略了所有类型 - 例如:
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个抽签的例子,但你必须有一个'一次性'最后.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);
}
这是最后一件事...最后一批抽奖......如果你试图在0,0时抽取它 - >这发生
寻求任何有用的反馈和/或理由为什么会发生这种情况 . 我是LibGdx的新手,不会回避你对我如何决定使用这个框架的反馈 .
谢谢你!
1 回答
因此,我缩小了导致它的原因:当你这样做时,它似乎不会被批错
1)在BASE类上实例化批处理2)在BASE类上调用batch.start渲染方法3)在batch.start之后调用BASE类中的一个抽象方法.4)批处理将被窃听 .
我为解决这个问题所做的是将批处理代码移动到派生类中,一切正常 .
我仍然对这个错误发生原因的答案持开放态度 .