2012-02-01 42 views
1

這是錯誤。爲什麼沒有合適的SurfaceView構造函數?

enter image description here

FastRenderView.java

package framework.impl; 
import android.graphics.Bitmap; 
import android.graphics.Canvas; 
import android.graphics.Rect; 
import android.view.SurfaceHolder; 
import android.view.SurfaceView; 
import framework.Game; 

public class FastRenderView extends SurfaceView implements Runnable { 

    Game game; 
    Bitmap frameBuffer; 
    Thread renderThread = null; 
    SurfaceHolder holder; 
    volatile boolean running = false; 

    public FastRenderView(Game game, Bitmap frameBuffer) { 
     super(game); 
     this.game = game; 
     this.frameBuffer = frameBuffer; 
     this.holder = getHolder(); 
    } 

    @Override 
    public void run() { 
     Rect dstRect = new Rect(); 
     long startTime = System.nanoTime(); 
     while(running) { 
      if(!holder.getSurface().isValid()) { 
       continue; 
      } 

      float deltaTime = (System.nanoTime() - startTime)/1000000000.0f; 
      startTime = System.nanoTime(); 

      game.getScreen().update(deltaTime); 
      game.getScreen().present(deltaTime); 

      Canvas canvas = holder.lockCanvas(); 
      canvas.getClipBounds(dstRect); 
      canvas.drawBitmap(frameBuffer, null, dstRect, null); 
      holder.unlockCanvasAndPost(canvas); 
     } 
    } 

    public void resume() { 
     running = true; 
     renderThread = new Thread(this); 
     renderThread.start(); 
    } 

    public void pause() { 
     running = false; 
     while(true) { 
      try { 
       renderThread.join(); 
       break; 
      } catch(Exception e) { 
       // retry 
      } 
     } 
    } 
} 

的問題是,上線19我得到的是上面顯示的錯誤 '超(遊戲);'

問題是我該如何解決這個問題?

如果您需要更多信息,請告訴我!

感謝您的幫助!

回答

1

在此參考看看:http://developer.android.com/reference/android/view/SurfaceView.htmlhttp://developer.android.com/reference/android/view/SurfaceView.html

當你調用super(),要傳遞的遊戲對象的父構造,這是SurfaceView的。由SurfaceView實現的唯一單參數構造函數需要一個上下文對象。 Game類是繼承鏈中某處的繼承嗎?

如果否,那麼你的問題。如果是,請發佈Game類的代碼。

+0

非常簡單的修復,我將第18行的遊戲更改爲AndroidGame,這樣我就可以獲得上下文。非常感謝! – Zeveso 2012-02-01 03:45:18

+0

沒問題!事實證明,這是一個比我預想的更簡單的問題,這太棒了! – Tom 2012-02-01 03:46:10

相關問題