2014-07-06 4 views
0

안녕하세요 여러분, 저는 안드로이드 그래픽에 멍청한 사람입니다. 내 게임에 대한 도움을 주시면 고맙겠습니다. 웬일인지 내 표면보기가로드되고 있지만 아무 것도 렌더링되지 않습니다 (그리 간단하지 않아야합니다.) 검정색 배경 만 렌더링됩니다. 어떤 도움도 감사 해 = D.표면보기에 아무 것도 표시되지 않습니다.

공용 클래스 startActivity를 활동 {

GameView gameView; 

Bitmap player; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_start); 

    //init our resources 
    // InitializeResources(); 


    gameView = new GameView(this); 

    player = BitmapFactory.decodeResource(getResources(),R.raw.inspector); 

    setContentView(gameView); 

} 



public void InitializeResources(){ 



    // sprite = new SpriteClass(gameView,player); 


} 




@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.start, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 


public void stop(){ 


} 


public void pause(){ 


} 





public class GameView extends SurfaceView implements Runnable { 


    Thread gamethread = null; 

    SurfaceHolder surfaceholder; 

    boolean canvasready = false; 




    public GameView(Context context) { 
     super(context); 

     surfaceholder = getHolder(); 

    } 


    @Override 
    public void draw(Canvas canvas) { 
     super.draw(canvas); 

     canvas.drawBitmap(player,0,0,null); 

    } 

    @Override 
    public void run() { 
     // if the canvas is ready draw to it 
     while(canvasready == true) 
     { 
      if(!surfaceholder.getSurface().isValid()) 
      { 
       continue; 
      } 

      Canvas c = surfaceholder.lockCanvas(); 

      gameView.setBackgroundColor(Color.WHITE); 

      c.drawBitmap(player,0,0,null); 



      surfaceholder.unlockCanvasAndPost(c); 

     } 


    } 

    public void Pause(){ 
     canvasready = false; 

     while(true) 
     { 
      try{ 
       //tries to stop the thread 
       gamethread.join(); 
      }catch(InterruptedException e){ 
       e.printStackTrace(); 

      } 

      break; 

     } 


     gamethread = null; 

    } 

    public void Resume(){ 
     canvasready = true; 
     gamethread = new Thread(this); 

     gamethread.start(); 

    } 

    public void stop(){ 


    } 



} 

}

답변

0

귀하의 콜백

체크 아웃의 몇 누락 다음 예

SurfaceView Example with SurfaceHolder

클래스해야 구현을 확장 SurfaceHo lder.Callback 및 기능을

holder.addCallback 전화 (이) 홀더 = D 수면

+0

는 그것이 다시 었음 홀더 실행 THX 인 –

관련 문제