gpt4 book ai didi

java - Spritebatch 未绘制任何 LibGDX

转载 作者:太空宇宙 更新时间:2023-11-04 11:50:14 25 4
gpt4 key购买 nike

对我来说,这是 LibGDX 中发生过的最奇怪的事情之一。我已经在游戏中的所有其他状态中使用了这些确切的规范,但在不同的名称下,它们都工作正常,除了我的 ShopState,它根本不会渲染任何东西!这是我的类(class)代码:

public class ShopState extends State{
private Texture bg;
private Sprite shopLayout;
private OrthographicCamera shopCam;
Viewport viewport;

public ShopState(GameStateManager gsm) {
super(gsm);
shopLayout = new Sprite(new Texture(Gdx.files.internal("shopLayout.png")));
bg = new Texture("bg2.png");
shopCam = new OrthographicCamera();
viewport = new StretchViewport(720, 1280, shopCam);
viewport.apply();
shopCam.position.set(shopCam.viewportWidth / 2, shopCam.viewportHeight / 2, 0);
shopLayout.setPosition(shopCam.viewportWidth / 2 - shopLayout.getWidth() / 2, shopCam.viewportHeight / 2 - shopLayout.getHeight() / 2);
shopLayout.setSize(650, 1100);
}

@Override
public void handleInput() {

}

@Override
public void update(float dt) {
handleInput();

}
@Override
public void resize(int width, int height){
viewport.update(width, height);
shopCam.position.set(shopCam.viewportWidth / 2, shopCam.viewportHeight / 2, 0);
}


@Override
public void render(SpriteBatch sb) {
shopCam.update();
sb.setProjectionMatrix(shopCam.combined);
sb.begin();
sb.draw(bg, 0 , 0, shopCam.viewportWidth, shopCam.viewportHeight);
shopLayout.draw(sb);
sb.end();

}

@Override
public void dispose() {
bg.dispose();
shopLayout.getTexture().dispose();

}
}

我做错了什么?一切看起来都很好,但是当我单击“商店”按钮时,我得到的只是黑屏!

最佳答案

好的,找到了解决方案,但我不知道为什么会解决这个问题。我所要做的就是添加一个使用当前视口(viewport)的舞台。

stage = Stage(viewport);

就是这样!由于某种原因,它现在可以正常工作......

关于java - Spritebatch 未绘制任何 LibGDX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41911869/

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