【发布时间】:2014-02-24 18:04:21
【问题描述】:
我的代码有问题,它出现在我开始使用步骤绘制 UI 之后,我使用 Batch 绘制了 3 个东西,Stage 绘制了一个带有 2 个按钮的舞台,但我的“Sprites”中只有 2 个"正在绘制中。代码如下:
public void render(float delta) {
Gdx.gl.glClearColor(0.95F, 0.95F, 0.95F, 0.95F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
deltaTime = Gdx.graphics.getDeltaTime();
camera.update();
generalUpdate(touch, camera, deltaTime, pointer);
bounce(deltaTime);
stage.setCamera(camera);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(Assets.spr_bg, 0, 0);
batch.draw(Assets.spr_title, 540-Assets.spr_title.getWidth()/2, titleY-Assets.spr_title.getHeight()/2);
Assets.font_small.draw(batch, "some text", 540-Assets.font_small.getBounds("(c)2014 HateStone Games").width/2, 1920-64-Assets.font_small.getBounds("(c) HateStone Games").height/2);
stage.draw();
batch.end();
}
是文本“Some text”没有被绘制出来,如果我把它注释掉,它就会发疯,标题精灵也没有被绘制出来,并且随机出现一个灰色框。
如果我移动“stage.draw();”在批次之外它不会被绘制
【问题讨论】:
-
您应该明确地将您的
stage.draw()移到batch.begin()-batch.end()块之外。两个绘图SpriteBatches 不能很好地协同工作......而且你不需要调用Gdx.Graphics.getDelta(),因为你的渲染方法中有一个参数delta。只是一些我会解决的问题。 -
它成功地将
stage.draw()移到批处理之后:) -
在我读完你问题的最后一句话后,我删除了我的答案xD
-
哈哈 xD 谢谢!
标签: java eclipse libgdx sprite spritebatch