2011-09-13 5 views
0

내 코드에 문제가 있습니다.android에서 게임 개발 : 캔버스에서 텍스트 회전

을 : 난 내 응용 프로그램은 즉시 종료됩니다 그렇게되면 내가 canvas.restore();

를 호출 할 수 있도록 ...

내 코드의 일부를 캔버스을 복원 내가 모든 작품의 텍스트를 회전하려고하지만 난 그렇게 할 때

터치 화면의 한 부분 :

if (wahrheitswert1 == true) { 
    x = 480; 
    y = 100;  

    // draw bounding rect before rotating text 
    Rect rect = new Rect(); 
    canvas.translate(x, y); 

    // undo the translate 
    canvas.translate(-x, -y); 
    // rotate the canvas on center of the text to draw 
    canvas.rotate(-180, x + rect.exactCenterX(), y + rect.exactCenterY()); 
    // draw the rotated text 
    canvas.drawText("Spieler1 touch", x, y, paint); 
    //undo the rotate 
    //canvas.restore(); 
    wahrheitswert1 = false; 
    canvas.restore(); 
} 

나는 배경 이미지가 화면의 다른 사이트에서 복사됩니다 가지고있는 비트 맵을 복원하지 마십시오. 도움을 주셔서 감사합니다.

답변

1

캔버스를 많이 사용하지는 않았지만 복원하기 전에 컨텍스트를 저장하는 위치가 표시되지 않습니다. 우선 컨텍스트를 저장해야하는 컨텍스트에서 복원을 수행해야합니다.

+0

사실을 저장하지 않고 복원 할 것이 없습니다 ... – WarrenFaith

+0

내가 무엇을해야하는지 말해 주시겠습니까? 저는 자바 전문가가 아닌 프로그래밍 전문가입니다 – kmartinho

+0

http://developer.android.com/reference/android/graphics/Canvas.html 에서 이전에 저장해야했던 복구 방법에 주목하십시오.). 기본적으로 복원 할 시점의 시점에서 canvas.save()를 호출하여 복원이 호출되면 저장된 점으로 복원합니다. – Contristo

0

당신은 캔버스를 회전하기 전에

Canvas.save() 

를 호출해야합니다. Canvas.save()를 호출하여 언제든지 Canvas를 복원 할 수 있습니다. 아래 코드를 수정했습니다.

if (wahrheitswert1 == true) { 
    x = 480; 
    y = 100; 

    canvas.save(); 

    // draw bounding rect before rotating text 
    Rect rect = new Rect(); 
    canvas.translate(x, y); 

    // undo the translate 
    canvas.translate(-x, -y); 
    // rotate the canvas on center of the text to draw 
    canvas.rotate(-180, x + rect.exactCenterX(), y + rect.exactCenterY()); 
    // draw the rotated text 
    canvas.drawText("Spieler1 touch", x, y, paint); 
    //undo the rotate 
    //canvas.restore(); 
    wahrheitswert1 = false; 
    canvas.restore(); 
} 

나는 또한 동일한 문제가있어서 나와 함께했습니다.