2016-08-28 9 views
0

自動的に呼び出される描画メソッドを停止する方法はありますか?どのような私が現在やっている面描画を自動的に呼び出すことから停止する

:私はrenderメソッドを呼び出すときだけにビューが再描画したい

public class GUI extends extends SurfaceView implements SurfaceHolder.Callback{ 

... 

public void render() { 
    SurfaceHolder surfaceHolder = getHolder(); 
    Canvas canvas = null; 
    try{ 
     canvas = surfaceHolder.lockCanvas(); 
     if (canvas != null) { 
      draw(canvas); 
     } 
    }finally { 
     if (canvas != null){ 
      surfaceHolder.unlockCanvasAndPost(canvas); 
     } 
    } 
} 

@Override 
public void draw(Canvas canvas){ 
... //things done with the canvas object 
} 
} 

public class Game extends AbstractGame { 

... 
@Override 
public void render(){ 
    this.graphicsPanel.render(); 
} 

は、私は(真)willNotDrawを設定しようとしたと虚偽が、それは違いはありません。どのように私は、自動的に描画から表面のビューを停止することができますが、それは正常です描画することができます53-59 fpsの平均ですが、ゲームのスレッド/リストとの衝突を避けるためにレンダリングを最後に行う必要があります

+0

あなたの問題を解決するかどうかを確認するには、[この質問のレビュー](http://stackoverflow.com/questions/3527621/how-to-pause-and-resume-a-surfaceview-thread)をご覧ください。 "Vijayaramanan"答えでは、異なるスコープを持つべきではないスレッドを混ぜ合わせてはいけません。エラー/例外が発生します。必要に応じて、ハンドラを使用してメインのLooperを取得し、メッセージを別のスレッド、およびperfomメソッドに投稿します。最後に、特定の時間にレンダリングを開始/停止する単一のSurfaceViewが必要な場合は、その単一の[onDraw()]をオーバーライドします(https://developer.android.com/training/custom-views/custom-drawing.html)。 'オブジェクト'。 – Bonatti

答えて

-1
Handle the scenario with thread in surface view class 

On resume of the activity start the thread of the surface view with 
Thread th; 
boolean isthreadStarted=false; 
public void OnResume(){ 
isthreadStarted=true; 
th=new Thread (this); 
th.start(); 
} 
public void 0nPause(){ 
isthreadStarted=true; 
if (th!=null){ 
th.join(); 
} 
} 

IN the render method check for isthreadStarted as true then call the draw method 

render(){ 
if (isthreadStarted){ 
// call your draw method 
draw (canvas); 
} 
} 

from your activity call this surface view onPause method to stop the canvas draw in this view 
+0

この方法はサーフェイスビューの描画を自動的に停止しますか? –

+0

はい、動作していない場合はお知らせください – Vijayaramanan

+0

setWillNotDraw(true)works –

関連する問題