Well, in my game while I'm drawing I have to verify the collision between the views. After a collision, I have to draw some things. But I can't draw them with a batch but with a stage. So I have to begin and end a lot of batches and this makes my game very slow.
Here is the part of code which I talked about:
for(int i=0;i<1000;i++)
{
if(i<999)
list.get(i+1).xTubo = list.get(i).xTubo + list.get(i).distanza;
for(int j=0;j<=60;j++)
{
if( (xPersonaggio==list.get(i).xTubo + j || xPersonaggio==list.get(i).xTubo-j*3)&& yPersonaggio<=list.get(i).altezza-50)
{
batch.begin();
if(ySalto==0)
batch.draw((TextureRegion) animation.getKeyFrame(time, true), orthographicCamera.position.x - 300, 60 + ySalto);
else
batch.draw(textureAtlas.createSprite("h"), orthographicCamera.position.x - 300, 60 + ySalto);
scrittaHaiPerso.draw(batch,"HAI PERSO!",orthographicCamera.position.x-50,500);
menu.draw(batch,"MENU",orthographicCamera.position.x,300);
batch.end();
stage.draw();
fineGioco=true;
}
}
batch.begin();
batch.draw(spriteTuboVerde,list.get(i).xTubo,-30,120,list.get(i).altezza);
batch.end();
if(xPersonaggio>list.get(i).xTubo+50)
tubiSaltati++;
}
In this cycle I draw a lot of views, as you can see at the bottom. At the top I have my very rudimental collision system. When a collision happens, an imagebutton appears on the screen and I have to draw it with a stage. So I have to begin and ends a lot of times the batch and this doesn't go well at all. How can I write less batches?
NOTE: The order of drawing has to be this