gpt4 book ai didi

java - libGDX 将正交相机向下移动纹理

转载 作者:行者123 更新时间:2023-11-30 09:21:24 26 4
gpt4 key购买 nike

我一直在尝试创建一个有人坠落的游戏。我的背景纹理的大小是 480x3200,我正在尝试创建游戏,以便相机在跌落时将人保持在屏幕中间,然后停在底部。但我无法让我的背景延伸到它开始的屏幕之外,然后才能看到图像的其余部分。

我现在所做的所有代码都是缩小 480x3200 图像以适合我当前的屏幕(我将其设置为 480x800),然后当人跌落时,背景不会改变。

这是我的 WorldRenderer 类,我在其中尝试做不同的事情,但每次,当图像开始向下移动时,我永远无法让人们看到图像的不同部分。

    public WorldRenderer(SpriteBatch b, World w) {
this.world = w;
this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
this.cam.position.set(CAMERA_WIDTH / 2, Person.position.y,0);
this.cam.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
this.cam.update();
spriteBatch = b;
loadTextures();
}

public void render(float delta) {
person = world.getPerson();

moveCamera();
cam.update();
spriteBatch.setProjectionMatrix(cam.combined);

spriteBatch.disableBlending();
spriteBatch.begin();
renderBackground();
spriteBatch.end();

spriteBatch.enableBlending();
spriteBatch.begin();
renderObjects();
spriteBatch.end();

}

private void moveCamera() {
cam.position.set(cam.position.x, Person.position.y, 0);
cam.update();
}

private void renderObjects() {
renderPerson();
renderBlocks();
renderPlatforms();
}

private void renderBackground() {
spriteBatch.draw(backgroundTexture, cam.position.x - CAMERA_WIDTH / 2, cam.position.y - CAMERA_HEIGHT / 2, CAMERA_WIDTH, CAMERA_HEIGHT);
}
}

有人有什么建议吗?

编辑:谢谢,我将 renderBackground 中的绘图更改为spriteBatch.draw(backgroundTexture,0,0, CAMERA_WIDTH, CAMERA_HEIGHT * 4); 现在可以使用了。

最佳答案

spriteBatch.draw(backgroundTexture, cam.position.x - CAMERA_WIDTH / 2,
cam.position.y - CAMERA_HEIGHT / 2, CAMERA_WIDTH, CAMERA_HEIGHT);

此代码绘制相对于相机位置的背景图像。这就是为什么改变相机的位置对背景图像的位置没有影响。把它改成这样:

spriteBatch.draw(backgroundTexture,0,0);

关于java - libGDX 将正交相机向下移动纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17035947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com