我目前正在为我的 libgdx 游戏制作一个简单的加载屏幕,但是它有一个问题。加载屏幕在 android 项目上完美运行,但在桌面版本上却无法正常工作。目前,加载屏幕应显示“LOADING”->“LOADING”。-> "LOADING.." -> "LOADING..." ,间隔 1 秒,然后重复。当我在桌面应用程序上加载游戏时,它显示“正在加载”(它像疯了一样闪烁),然后按照预期的时间进行。整个时间一切都在闪烁,就像刷新率太高之类的一样,它会在后台显示不应该存在的幻象周期。有人能告诉我这是什么时候发生在桌面版本而不是 Android 版本上吗?这也是我的“LoadingScreen 实现屏幕”的两个功能的代码
渲染(浮点增量)函数:
float updateTextTime = 0;
@Override
public void render(float delta) {
if (updateTextTime >= 1){ //check to see if it has been a second
if (periods == 0){
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); //clears the buffer bit
}
textBatch.begin();
font.draw(textBatch,loading.substring(0,7+periods),(Gdx.graphics.getWidth()/2)-(textwidth/2),(Gdx.graphics.getHeight()/2)+(textheight/2));
if (periods < 3){
periods += 1;
}else{
periods = 0;
}
textBatch.end();
updateTextTime = 0;
}else{
updateTextTime += delta; //accumlate
}
}
和 show() 函数:
@Override
public void show() {
textBatch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("fonts/ArmyChalk.fnt"), Gdx.files.internal("fonts/ArmyChalk.png"),false);
if (game.AppTypeMine == ApplicationType.Android){
font.scale(2.0f);
}
textwidth = font.getBounds(loading).width;
textheight = font.getBounds(loading).height;
}
最终解决方案:更改了 render() 函数:public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
textBatch.begin();
font.draw(textBatch,loading.substring(0,7+periods),(Gdx.graphics.getWidth()/2)-(textwidth/2),(Gdx.graphics.getHeight()/2)+(textheight/2));
textBatch.end();
if (updateTextTime >= 0.5){ //check to see if it has been a second
if (periods < 3){
periods += 1;
}else{
periods = 0;
}
updateTextTime = 0;
}else{
updateTextTime += delta; //accumlate
}
}