SpriteBatch设置在libgdx中Actor的级别之下

时间:2015-11-16 14:03:12

标签: java android-studio libgdx actor spritebatch

我在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(); 

1 个答案:

答案 0 :(得分:0)

解决方案,在方法渲染结束时移动stage.act()和stage.draw():

//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();