Java 桌面应用程序中简单libgdx示例的低帧率
我刚开始学习libGDX,并遵循了(libGDX帮助页面上的第二个链接)中的示例 现在,我只显示了512x512的徽标。在应用程序中没有其他事情发生,但当我在桌面模式下运行应用程序时,我得到的FPS为15-16。当我删除图像,我得到了60FPS的空白屏幕。对于android来说更糟糕的是,我在Galaxy SL-GT-i9003中获得了3-4 fps(Temple Run在设备上以可玩速度运行) 我的笔记本电脑在玩魔兽世界时没有任何质量问题,所以这么小的应用程序只能达到15fps,这让我很困惑Java 桌面应用程序中简单libgdx示例的低帧率,java,android,libgdx,frame-rate,Java,Android,Libgdx,Frame Rate,我刚开始学习libGDX,并遵循了(libGDX帮助页面上的第二个链接)中的示例 现在,我只显示了512x512的徽标。在应用程序中没有其他事情发生,但当我在桌面模式下运行应用程序时,我得到的FPS为15-16。当我删除图像,我得到了60FPS的空白屏幕。对于android来说更糟糕的是,我在Galaxy SL-GT-i9003中获得了3-4 fps(Temple Run在设备上以可玩速度运行) 我的笔记本电脑在玩魔兽世界时没有任何质量问题,所以这么小的应用程序只能达到15fps,这让我很困惑
public class SplashScreen extends AbstractScreen {
private Texture splashTexture;
private TextureRegion splashTextureRegion;
public SplashScreen(MyGDXGame game){
super(game);
}
@Override
public void show()
{
super.show();
// load the splash image and create the texture region
splashTexture = new Texture("splash.png");
// we set the linear texture filter to improve the stretching
splashTexture.setFilter( TextureFilter.Linear, TextureFilter.Linear );
// in the image atlas, our splash image begins at (0,0) at the
// upper-left corner and has a dimension of 512x301
splashTextureRegion = new TextureRegion( splashTexture, 0, 0, 512, 382 );
}
@Override
public void render(float delta ) {
super.render( delta );
// we use the SpriteBatch to draw 2D textures (it is defined in our base
// class: AbstractScreen)
batch.begin();
// we tell the batch to draw the region starting at (0,0) of the
// lower-left corner with the size of the screen
batch.draw( splashTextureRegion, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() );
// the end method does the drawing
batch.end();
}
@Override
public void dispose()
{
super.dispose();
splashTexture.dispose();
}
}
以下是AbstractScreen类的相关部分:
public class AbstractScreen implements Screen {
protected final MyGDXGame game;
protected final BitmapFont font;
protected final SpriteBatch batch;
public AbstractScreen(MyGDXGame game ){
this.game = game;
this.font = new BitmapFont();
this.batch = new SpriteBatch();
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor( 0f, 0f, 0f, 1f );
Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
}
...
}
和桌面应用程序:
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "First Game";
cfg.useGL20 = false;
cfg.width = 800;
cfg.height = 480;
new LwjglApplication(new MyGDXGame(), cfg);
}
MyGDXGame如下所示:
public class MyGDXGame extends Game {
private FPSLogger fpsLogger;
public SplashScreen getSplashScreen() {
return new SplashScreen( this );
}
@Override
public void create() {
fpsLogger = new FPSLogger();
}
@Override
public void dispose() {
super.dispose();
}
@Override
public void render() {
super.render();
setScreen(getSplashScreen());
fpsLogger.log();
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void pause() {
super.pause();
}
@Override
public void resume() {
super.resume();
}
我读过很多关于libGdx的好东西,所以这个问题对我来说似乎很困惑。获得如此低的帧速率,我做错了什么?我认为setScreen(getSplashScreen())问题可能是render()
方法中的code>。将其移动到MyGDXGame
的create()
方法
现在,您正在每一帧切换屏幕,并且每次都重新创建一个非常沉重的SpriteBatch
(请参阅我对您的问题的评论)。到目前为止,代码看起来还不错。我不会对每个屏幕使用一个SpriteBatch,但它不能对帧速率限制那么多。请给我们看MyGDXGame
。Amd尝试启用GL20并设置配置的前置FPS。您使用哪个libgdx和java版本?感谢您对SpriteBatch的评论。我将在稍后添加MyGDX。我使用的是libgdxv0.9.9和java1.7。GL20未更改桌面上的帧速率,手机不支持GL2.0。我在桌面和手机上都运行了MetalGun,它们的帧速率分别达到60和50。在v0.9.9的LWJGLAPPLICATION配置中没有可设置的前置FPS。我尝试禁用vSYnc和usecpusync,但在桌面模式下,我的FPS似乎仍然限制在16。由于这些设置不影响Android,所以没有更改。没有foregroundFPS?两天前,我切换到0.9.9,但仍然存在此设置。没有GL 2?那么它就是那种0.8%的恐龙手机之一:)谢谢。每次渲染屏幕时,我都没有捕捉到对象,这太愚蠢了。我移动了代码“setScreen(getSplashScreen());”现在我在桌面模式和设备上以60 FPS的速度运行。