Libgdx虚拟宽度和高度

时间:2013-08-11 06:28:01

标签: java libgdx screen-resolution

我正在学习本教程:http://www.java-gaming.org/index.php?topic=25685.new并使用虚拟宽度和高度。

我的要求是:

  1. 背景图片应该填满整个屏幕

  2. 应保留游戏资产的宽高比:我的虚拟宽度,高度为:800,600。其中一个游戏资产有初始虚拟位置:450,20,所以我设置:

    playerSprite.setPosition(450, 20);//I assume (450,20) would be virtual
    
  3. 问题是当我通过主要功能将窗口大小设置为200X200时,播放器(游戏资产)不可见。我认为资产(大小和位置)会自动缩放保留的宽高比。但是,当我将屏幕大小设置为800X600,然后将其大小调整为200X200(手动)时,资产将按比例缩放并正确定位。我没有在主要功能中设置200X200与之后将大窗口调整为200X200之间的区别。

    我的渲染功能:

    Gdx.gl.glClearColor(0, 0, 0, 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    //Stretch background to cover the entire screen
    if(backgroundTR!=null){
    //Gdx.gl.glViewport(0, 0, screenWidth, screenHeight);
        batch.begin();
    batch.draw(backgroundTR, 0, 0,screenWidth,screenHeight);
    batch.end();
    }
    
    //Preserve aspect ratios of assets as per the tutorial
    orthographicCamera.update();
    orthographicCamera.apply(Gdx.gl10);
    Gdx.gl.glViewport((int)viewport.x, (int)viewport.y, (int)viewport.width, (int)viewport.height);
    
    batch.begin();
    batch.draw(titleTR,160f,450f);
        //batch.draw(playerTR,450f,20f);
    playerSprite.draw(batch);
    batch.end();
    

    背景也未填充。有什么帮助吗?

0 个答案:

没有答案
相关问题