1
votes

I'm making a game in libgdx , and I've added different Actor forming my scene . Currently however, I added a texture:

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

and in the render() method:

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

everything works , repeat the effect goes to great ... but my problem is that I covers all Actor as if their z- index was lower than the background . And ' you can indicate the spritebatch to remain lower than the actors ?

EDIT SOLUTION set render() method like this:

//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
I'm sorry if I misunderstood something about your question, but what is the drawing order of the actors and the background? They will be ordered the same way they are sent to the batch. If the background is being drawn after the other actors that might be your problem, but it's been a while since I used Libgdx. I don't think there is a z-order anywhere, you'll have to render in the right order.stonecompass
It looks like you've figured it out, as Hypo suggested. Rather than editing it into your question you could post it as an answer at the bottom of page and accept it later. (It's fine to answer your own question)- You'll get more points for it and its more clear to other users that there is a solution, as well as what the solution wasDoubleDouble
thanks , I've answered my question .Mr. Developer

1 Answers

0
votes

Solution, move the stage.act() and stage.draw() on the end the method 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();