我确定我在这里很明显地遗漏了一些东西,但是我是初学者,所以请不要迷恋我。我的问题是,我的舞台的视口比屏幕小。现在我也想直接使用Sprite.draw(SpriteBatch)在屏幕上绘制一个Sprite。Sprite和舞台的位置不重叠。舞台绘制得很好,但Sprite不可见。当我注释掉渲染方法中的stage.draw()部分时,Sprite可见。
代码:这是我的渲染方法:
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.851f, 0.894f, 0.992f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
stage.act(delta);
batch.setProjectionMatrix(camera.combined);
batch.begin();
stage.draw();
logoSprite.draw(batch);
batch.end();
}
在这里,我初始化相机和舞台(stageHeight是一个仅是屏幕高度3/5 *的int):
camera = new OrthographicCamera();
camera.setToOrtho(false, SwapItGame.WIDTH, SwapItGame.HEIGHT);
stage = new Stage();
stage.setViewport(1080, stageHeight, true, 0, 0, 1080, stageHeight); //The button part of the menu takes up 3 fifth of the Height of hte screen
stage.setCamera(camera);
在这里,我初始化了Sprite(Sprite的位置值非常复杂,只需忽略它即可。它肯定在舞台上方):
logoSprite = skin.getSprite("logo");
logoSprite.setPosition((SwapItGame.WIDTH-logoSprite.getWidth())/2, (SwapItGame.HEIGHT-stageHeight-logoSprite.getHeight())/2 + stageHeight);
在同一屏幕上不可能有精灵和舞台吗?还是我做的事情根本上是错的?
尝试移动
stage.draw();
以上批处理操作
stage.draw();
batch.setProjectionMatrix(camera.combined);
batch.begin();
logoSprite.draw(batch);
batch.end();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句