[英]LIbgdx Background Image issue
所以这是我的问题。 我有一个 800x800 libgdx 游戏,我使用 gimp 创建了一个 800x800.png。 我添加它并绘制它,但现在图像似乎比预期的要大得多。 例如,如果我有一个 ocean.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();
}
根据我的测试,您的相机的视口似乎配置不正确。 如果您使用的是 OrthographicCamera,那么您想使用 OrthographicCamera.setToOrtho() 来设置视口。 现在,相机设置为显示图像的 2x2 像素角。 但是,您的示例不可复制,我不知道您如何设置 SpriteBatch 或相机,或任何与此相关的东西,所以我可能会离开。
PS为什么在img和纹理区域相同的情况下绘制它们? img 只会将图像放在左下角,textureRegion 会在屏幕上重复几次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.