我正在 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 保持低于 Actor 吗?
编辑解决方案设置 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();
最佳答案
解决方案,将 stage.act() 和 stage.draw() 移到 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();
关于java - SpriteBatch 设置在 libgdx 中 Actor 级别以下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33737247/