Exemplo n.º 1
0
  @Override
  public void run() {

    long tickPS = 1000 / FPS;
    long startTime;
    long sleepTime;

    while (isRunning) {
      Canvas c = null;
      startTime = System.currentTimeMillis();
      try {
        c = gameView.getHolder().lockCanvas();
        synchronized (gameView.getHolder()) {
          gameView.draw(c);
        }
      } finally {
        if (c != null) {
          gameView.getHolder().unlockCanvasAndPost(c);
        }
      }
      sleepTime = tickPS - (System.currentTimeMillis() - startTime);
      try {
        if (sleepTime > 0) sleep(sleepTime);
        else sleep(10);

      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
  @Override
  public void run() {
    long ticksPS = 1000 / FPS;
    long startTime;
    long sleepTime;

    while (running) {
      mGameCanvas = null;
      startTime = System.currentTimeMillis();

      try {
        mGameCanvas = mGameView.getHolder().lockCanvas();
        synchronized (mGameView.getHolder()) {
          mGameView.update();
          if (mGameCanvas != null) mGameView.draw(mGameCanvas);
        }
      } finally {
        if (mGameCanvas != null) {
          mGameView.getHolder().unlockCanvasAndPost(mGameCanvas);
        }
      }
      sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
      try {
        if (sleepTime > 0) sleep(sleepTime);
        else sleep(10);
      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 3
0
 @Override
 public void run() {
   while (running) {
     Canvas c = null;
     try {
       c = view.getHolder().lockCanvas();
       synchronized (view.getHolder()) {
         view.onDraw(c);
       }
     } finally {
       if (c != null) {
         view.getHolder().unlockCanvasAndPost(c);
       }
     }
   }
 }
Exemplo n.º 4
0
  public GameThread(GameView gameView) {
    mGameView = gameView;

    mSurfaceHolder = gameView.getHolder();
    mHandler = gameView.getmHandler();
    mContext = gameView.getContext();

    mBackgroundImage =
        BitmapFactory.decodeResource(
            gameView.getContext().getResources(), R.drawable.background_hd);
  }
Exemplo n.º 5
0
 /** Request the device to draw */
 @SuppressLint("WrongCall")
 private void updateEngine() {
   try {
     startDraw();
     synchronized (view.getHolder()) {
       view.onDraw(c);
     }
   } finally {
     if (c != null) {
       endDraw(c);
     }
   }
 }
Exemplo n.º 6
0
 /** Start drawing on the canvas */
 public final void startDraw() {
   c = view.getHolder().lockCanvas();
   if (c == null) Log.d("GameThread", "Canvas is null");
 }
Exemplo n.º 7
0
 /**
  * Stop Drawing
  *
  * @param c Canvas that needs to be stop drawing
  */
 public final void endDraw(Canvas c) {
   view.getHolder().unlockCanvasAndPost(c);
 }