surfaceview portage 1.5 other version of android

Problems with Canvas, OpenGL, etc...

surfaceview portage 1.5 other version of android

Postby fubus » Mon Jul 05, 2010 8:49 am

Sorry for my english i'm french !
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()));
      }
   }

}
fubus
Freshman
Freshman
 
Posts: 7
Joined: Mon Jul 05, 2010 8:40 am

Top

Re: surfaceview portage 1.5 other version of android

Postby fubus » Wed Jul 07, 2010 10:05 am

I find the mistakes !!!
The problem is after android 1.5 a surfaceview can't be refresh more 40-45 time per second so i reduce my fps to 30 and i accelerate the speed of my game
fubus
Freshman
Freshman
 
Posts: 7
Joined: Mon Jul 05, 2010 8:40 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest