I realized a 2d game on android 1.5, it works perfectly on my HTC Hero 1.5. But Yesterday, i want to install my game on a sony xperia x10 1.6 and the game is very slowly (20 FPS less) and i don't understand.
My thread who refresh my game 60 times per second
- Code: Select all
public class ThreadRefresh extends Thread{
private EcranPrincipale panel;
private boolean run = false;
protected boolean gameover=false;
final int FRAMES_PER_SECOND = 60;
final int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
long next_game_tick;
int sleeptime;
public ThreadRefresh( EcranPrincipale panel) {
this.panel = panel;
next_game_tick = SystemClock.uptimeMillis();
sleeptime=0;
}
public void setRunning(boolean run) {
this.run = run;
}
@Override
public synchronized void run() {
Canvas c;
while (run) {
c = null;
try {
c = panel.getHolder().lockCanvas();
synchronized ( panel.getHolder()) {
// if(gameover){
// FinPartie fp=new FinPartie();
// fp.onDraw(c);
// }else{
panel.update();
panel.onDraw(c);
//}
next_game_tick += SKIP_TICKS;
long temptimemilli= SystemClock.elapsedRealtime();
sleeptime = (int) (next_game_tick - temptimemilli);
//next_game_tick = temptimemilli;
// android.util.Log.e("sleep", ""+sleeptime+" : "+temptimemilli +" : "+next_game_tick);
if( sleeptime >= 0 ) {
try {
sleep(sleeptime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else
next_game_tick = SystemClock.elapsedRealtime();
Paint paint = new Paint();
paint.setColor(Color.WHITE);
c.drawText(" fps : "+(60+sleeptime), 0, 95, paint);
}
}finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
panel.getHolder().unlockCanvasAndPost(c);
}
}
//android.util.Log.e("fps", ""+1000/(next_game_tick - SystemClock.currentThreadTimeMillis()));
}
}
}


