Reputation: 117
My project runs perfectly fine on the desktop version but it keeps on flickering when testing on android.
i have done lots of research about this and apparently the problem cause double buffering. but still i couldnt find any solution for that yet. there was a guy that sugested using "render to texture" but i couldnt find any example about that for libgdx.
i want to know if there is a way to solve this issue
in case you wanna know about my code i have a draw spritebatch out side the render function where i had to do that to go with my game logic and that is what cuasing the double buffering
public void create(){
...
Gdx.graphics.setContinuousRendering(false);
Gdx.graphics.requestRendering();
}
public void render() {
batch.begin();
drawBoard();
player();
batch.end();
}
where my player function checks whos turn (player1/player2) then it checks legal moves then it draws the spritebatch according to that
public void player(){
clickX=Gdx.input.getX();
clickY=(Gdx.input.getY()-Gdx.graphics.getHeight())*-1;
if(turn==true){
player = "player1";
if(Gdx.input.isTouched()){
//System.out.println("avalible");
if(rect.isEmpty()){
batch.setColor(Color.WHITE);
addLineNew(clickX, clickY);
plr1++;
System.out.println(plr1);
turn=false;
}else {
for (int i=0; i<rect.size(); i++){
if(rect.get(i).contains(clickX, clickY)){
System.out.println("line exsit");
break;
}else{
batch.setColor(Color.WHITE);
tempScore = score1;
turnC=added.size();
addLineNew(clickX,clickY);
System.out.println("rect size "+rect.size());
if(turnC>added.size()){
calculateScore();
}
plr1++;
System.out.println(plr1);
if (score1>tempScore){
turn=true;
}else if (turnC>added.size()){
turn=false;
}else{
turn=true;
}
break;
}
}
this is for player1 for player 2 is pretty much the same
public void addLineNew(float x, float y){
float clickx=x;
float clicky=y;
outterLoop:
for (int i=0; i<added.size(); i++){
for(int j=0; j<Xpoints.length; j++){
if(added.get(i).contains(clickx, clicky) && added.get(i).x==Xpoints[j]+16){
batch.draw(lineH, added.get(i).x, added.get(i).y, sizeH.x, sizeH.y);
rect.add(added.get(i));
added.remove(i);
System.out.println("sizz///"+added.size());
break outterLoop;
}
else if (added.get(i).contains(clickx, clicky) && added.get(i).x==Xpoints[j]){
batch.draw(line, added.get(i).x, added.get(i).y, sizeV.x, sizeV.y);
rect.add(added.get(i));
added.remove(i);
System.out.println("sizz///"+added.size());
break outterLoop;
}
else{
System.out.println("line is not availble play again");
}
}
add line function where im using it to draw
Upvotes: 3
Views: 559
Reputation: 7114
You did something wrong. :) Try creating that demo project with bucket and rain drops and see does it also has flickering screen.
If it also flickers then you should try your app on some other phone/tablet.
But if it doesn't then compare main rendering steps (and their order) in that demo with your app.
What I do when I'm desperate is that I start with working code and start changing it peace by peace until it becomes identical with non-working or actually at some point it will stop working, so you'll know what you changed last..
Upvotes: 1