2011-09-13 10 views
0

私のコードに問題があります。アンドロイドで開発中のゲーム:キャンバス内のテキストの回転

:私はすべての作品テキストを回転しようとするが、私はそうキャンバスを復元したい場合は、私は私のアプリがすぐにシャットダウンすることを行うと私は私のコードの一部

... 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

私は何をすればいいのか教えてください。 私はJavaのエキスパートではなくプログラミングを始めました。 – 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(); 
} 

私も同じ問題を抱えていて、それは私のために働いていました。

関連する問題