![](/img/trans.png)
[英]Sprite class not drawn when using Sprite.draw(batch) LibGDX
[英]libGdx: Sprite is not drawn when there is a stage
我確定我在這里遺漏了一些非常明顯的東西,但我是初學者所以請不要壓垮我。 我的問題是我有一個視口小於屏幕的舞台。 現在我還想直接使用Sprite.draw(SpriteBatch)在屏幕上繪制一個Sprite。 Sprite和舞台的位置不重疊。 舞台繪制得很好,但Sprite不可見。 當我在render-method中注釋掉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(精靈的位置值相當復雜,只是忽略它。它肯定在舞台之上):
logoSprite = skin.getSprite("logo");
logoSprite.setPosition((SwapItGame.WIDTH-logoSprite.getWidth())/2, (SwapItGame.HEIGHT-stageHeight-logoSprite.getHeight())/2 + stageHeight);
是不可能在同一個屏幕上有一個Sprite和一個舞台? 還是我做了一些根本錯誤的事情?
試着移動
stage.draw();
以上批量操作
stage.draw();
batch.setProjectionMatrix(camera.combined);
batch.begin();
logoSprite.draw(batch);
batch.end();
我知道這是舊的,但如果您不能或不想移動stage.draw()方法,只需在stage.draw()之前調用batch.end(),然后重啟批處理馬上......我在我的游戲中使用不同的游戲屏幕狀態並試圖移動我的stage.draw()並且它只破壞了我班級中的其他東西所以我終於嘗試了這個,這就像一個魅力和如果上述解決方案不能輕松工作,可以幫助某人。
batch.end();
stage.draw();
batch.begin();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.