LibGDX - 如何使用相机扩展艺术作品?

时间:2014-03-08 17:47:57

标签: libgdx

我一直在阅读有关OrthographicCamera的内容,但我不确定我是否正确使用了我的艺术资料。 首先让我说我的所有艺术都是用于iphone5显示屏(1136 * 640)。 现在,我正在使用2 OrthographicCamera s

  1. 5米* 5米的尺寸 - 这款相机在游戏中跟随我的主角。
  2. 尺寸为800px * 640px - 此相机用于在屏幕上渲染内容,如得分,生活等。
  3. 现在我正在尝试使用第一台相机来渲染我的艺术品,所以例如我有一个png图像, 我如何根据我定义的相机知道如何缩放它(记住,它是5米* 5米)? 我不能只说它是1米(世界大小的1/5),因为图像看起来很糟糕,我想保持它的原始大小,让框架根据手机大小进行缩放。

    我目前的代码如下:

    OrthographicCamera worldCamera; // 5 meters * 5 meters
    OrthographicCamera sceneCamera; // 800px*640px
    SpriteBatch batch;
    
    @Override
    public void render() {
        batch.setProjectionMatrix(sceneCamera.combined);
        batch.begin();
        //render background using Gdx.graphics.getWidth() and Gdx.graphics.getHeight()
        batch.end();
    
        batch.setProjectionMatrix(sceneCamera.combined);
        batch.begin();
        //render "static" elements, score lives etc..
        batch.end();
    
        batch.setProjectionMatrix(worldCamera.combined);
        batch.begin();
        //render "movable" elements - how do I scale them here? I want their original size!
        batch.end();
    }
    

0 个答案:

没有答案