【问题标题】:LIbgdx Background Image issueLIbgdx 背景图像问题
【发布时间】:2021-05-14 16:04:33
【问题描述】:

所以这是我的问题。我有一个 800x800 libgdx 游戏,我使用 gimp 创建了一个 800x800 .png。我添加它并绘制它,但现在图像似乎比预期的要大得多。例如,如果我有一个海洋 .png,则呈现的只是深蓝色屏幕。似乎它正在接受我的形象,但我做错了其他事情。任何帮助都是极好的。代码如下。玩家和敌人都渲染得很好并且在蓝色之上。

private Texture img;
private TextureRegion textureRegion;
float drawingWidth,drawingHeight;

//Constructor
public GameScreen(Game game) {
    this.game = game;
    img = new Texture("tester2.png");
    img.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.ClampToEdge);
    int width=Gdx.graphics.getWidth();

    textureRegion=new TextureRegion(img,0,0,width,img.getHeight());

    drawingWidth=width;
    drawingHeight=Gdx.graphics.getHeight(); 
    
    Gdx.app.log(ID, "GameScreen is loaded! " + drawingWidth + " " + drawingHeight);
}

@Override
public void render(float deltaTime) {
    //buffer screen
    Gdx.gl20.glClearColor((11f / 255.0f), (11f / 255.0f), (11f / 255.0f), 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
    sb.begin();     
    sb.setProjectionMatrix(camera.combined);
    update(deltaTime);
    sb.draw(textureRegion,0,0,drawingWidth,drawingHeight);
    sb.draw(img, 0, 0);
    player.render(sb);
    enemy.render(sb);
    sb.end();
}

【问题讨论】:

    标签: java libgdx rendering


    【解决方案1】:

    根据我的测试,您的相机的视口似乎配置不正确。如果您使用的是 OrthographicCamera,那么您想使用 OrthographicCamera.setToOrtho() 来设置视口。现在,相机设置为显示图像的 2x2 像素角。但是,您的示例不可复制,我不知道您如何设置 SpriteBatch 或相机,或者任何与此相关的东西,所以我可能会离开。

    附:当它们相同时,为什么要绘制 img 和纹理区域? img 只会将图像放在左下角,textureRegion 会在屏幕上重复几次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      • 2018-04-18
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多