除非移动窗口,否则libgdx相机会冻结

时间:2017-10-20 20:04:13

标签: java camera libgdx rendering

我现在一直在玩LibGDX并且没有找到一个我直到现在都无法解决的问题。当我运行我的项目时,一切都运行得很好,但是大约十分之一的相机会拒绝更新它似乎除非游戏窗口是在另一个程序现有的窗口或我用鼠标物理抓住窗口并移动它移动我的精灵,以便我可以看到它更新。有谁有任何想法可能导致这个?

@Override
public void create () {
    int tileSize = 16;
    int w = 30 * tileSize;
    int h = 17 * tileSize;
    viewport.setScreenSize(w, h);

    camera = new OrthographicCamera();
    camera.setToOrtho(false,viewport.getScreenWidth(),viewport.getScreenHeight());
    camera.update();


    mapGenerator = new MapGenerator();

    tiledMapRenderer = new OrthogonalTiledMapRenderer(mapGenerator.getTiledMap());

    spawner = new EntitySpawner(mapGenerator.getMapObjects());
    spawner.spawn();//there is a to do in the entity spawner class to move this else where

    sb = new SpriteBatch();

    hud = new Hud(camera);

    Gdx.input.setInputProcessor(this);

    Gdx.graphics.setResizable(false);//makes it so you can't just drag the game window to any size since its easy to distort it
    Gdx.graphics.setWindowedMode(1280,720);//resolution size windowed
}

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);//background color
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    //update the camera
    camera.position.x = spawner.player.sprite.getX();
    camera.position.y = spawner.player.sprite.getY();
    camera.update();
    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();

    timeElapsed += Gdx.graphics.getDeltaTime();//simply time that has passed based off delta time


    sb.setProjectionMatrix(camera.combined);
    sb.begin(); //start the sprite batch
    spawner.draw(sb);//draw any entities with the spawner

    hud.draw(sb);//draw the HUD
    sb.end();//end the sprite batch

}

0 个答案:

没有答案
相关问题