2013-01-05 1 views
0

누구나 캔버스의이 그림을 반복하는 방법을 알고 있습니까? 나중에 onTouch 메서드를 추가하고 X 위치를 얻고 싶습니다. 고맙습니다.안드로이드에서 캔버스 루핑

@Override 
protected void onDraw(Canvas canvas) { 
    //Canvas canvas= new Canvas(); 
    xp1 = canvas.getWidth()/2; 
    Log.d("test1", "It went pass onDraw"); 
    xp2 = canvas.getWidth()/2; 
    yp1 = 25; 
    yp2 = 760; 
    canvas.drawColor(Color.BLACK); 
    canvas.drawBitmap(paddle1, xp1,yp1, null); 
    canvas.drawBitmap(paddle2,xp2,yp2, null); 
    Paint white = new Paint(); 
    white.setColor(Color.WHITE); 
    canvas.drawText("Score P1:"+ p1Score +" P2: " + p2Score , 700, 20,white); 
    Log.d("test1", "It's done with onDraw"); 

} 
+1

그것은 _canvas_을 _loop_ 것은 무엇을 의미 하는가? –

+0

캔버스 그리기 계속 하시겠습니까? –

답변

1

호출 방법

invalidate(); 

당신이 'onDraw' 방법에 콜백을 할 때마다

aSampleCode(){ 
     image.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 

       switch(event.getAction()) 
       { 
       case MotionEvent.ACTION_MOVE: 

        x= event.getRawX() 

        break; 
       case MotionEvent.ACTION_UP: 
            invalidate(); 
        break; 
       case MotionEvent.ACTION_DOWN: 
        break; 

       default: 
        break; 
       } 
       return true; 
      } 
     }); 
    } 
} 
+0

메신저에서 null 포인터 예외가 발생합니다. –

+0

예외 로그? –