@Override public void run() { this.run = true; Canvas c = null; while (run) { try { c = this.surfaceHolder.lockCanvas(null); synchronized (this.surfaceHolder) { currentTime = System.currentTimeMillis(); if (currentTime > previousTime + mFPS || true) { previousTime = currentTime; updatePhysics(); mario.update(currentTime); sprCoin.Update(currentTime); sprBlock.Update(currentTime); pipePlant.Update(currentTime); if (pipePlant.getYPos() <= this.pipePlantInitY) { pipePlant.setYVel(1); } if (pipePlant.getYPos() >= this.pipePlantInitY + 70) { pipePlant.setYVel(-1); } doDraw(c); } } } finally { if (c != null) { this.surfaceHolder.unlockCanvasAndPost(c); } } // pause if no need to animate synchronized (this) { if (wait) { try { wait(); } catch (Exception e) { } } } } }