对我来说,这是LibGDX中最奇怪的事情之一。我已经在我的游戏中使用了所有其他状态的这些确切的规格,但是在不同的名称下它们都工作得很好,除了我的ShopState,它根本没有渲染任何东西!这是我的课程代码:
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();
}
}
我做错了什么?一切似乎都很好,但是当我点击商店按钮时,我得到的只是黑屏!
答案 0 :(得分:0)
好的,找到了一个解决方案,但我不知道为什么要修复它。我所要做的就是添加一个使用当前视口的舞台。
stage = Stage(viewport);
就是这样!由于某种原因,它现在正常工作......