SpriteBatch 设置低于 libgdx 中的 Actor 级别

SpriteBatch set below the level of the Actor in libgdx

我正在 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 保持低于演员吗?

编辑解决方案 像这样设置 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();