【发布时间】:2016-02-17 15:52:48
【问题描述】:
我正在 libgdx 中制作游戏,并添加了不同的 Actor 来形成我的场景。 然而,目前,我添加了一个纹理:
//other variables:
Texture texture; int sourceX = 0;
//create() method
texture = new Texture(Gdx.files.internal("background.png"));
texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
...other code...
stage.addActor(actorMen);
在 render() 方法中:
//render() method
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
sourceX+=10;
batch.begin();
batch.draw(texture, 0, 0, sourceX, 0, (int) background.getWidth(), (int) background.getHeight());
batch.end();
一切正常,重复效果非常好……但我的问题是我覆盖了所有 Actor,就好像它们的 z-index 低于背景一样。 ' 你可以指示 spritebatch 保持低于演员?
EDIT SOLUTION 设置 render() 方法如下:
//render() method
sourceX+=10;
batch.begin();
batch.draw(texture, 0, 0, sourceX, 0, (int) background.getWidth(), (int) background.getHeight());
batch.end();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
【问题讨论】:
-
如果我对你的问题有误解,我很抱歉,但是演员和背景的绘制顺序是什么?它们的订购方式与发送到批次的方式相同。如果背景是在其他演员之后绘制的,那可能是您的问题,但是自从我使用 Libgdx 以来已经有一段时间了。我认为任何地方都没有 z 顺序,您必须以正确的顺序进行渲染。
-
看起来你已经明白了,正如 Hypo 所建议的那样。您可以将其作为答案发布在页面底部并稍后接受,而不是将其编辑到您的问题中。 (回答你自己的问题很好)- 你会得到更多的分数,并且其他用户更清楚有解决方案,以及解决方案是什么
-
谢谢,我已经回答了我的问题。
标签: java android-studio libgdx actor spritebatch