2014-12-19 55 views
1

儘管其他繪畫調用工作得非常好,但仍然無法處理canvas.drawText(...)方法(但不渲染任何東西)。例如,我在畫布上繪製線條/位圖,但繪製文字仍然失敗。Android DrawText不能在SurfaceView上工作

訂購:MainActivity - > GameActivity - > GameThread:主題 - >的GamePanel:SurfaceView

代碼: 公共無效渲染(帆布油畫){ canvas.drawColor(Color.BLACK);

//draws the vector line! 
    if(this.PAUSED == 2) 
     this.drawLine(canvas); 
    playerOne.render(canvas); 
    for(int a=0; a < GameConstants.floatingStructures.size(); a++) 
    { 
     GameConstants.floatingStructures.get(a).render(canvas);//renders each item to the canvas 
    } 

    Paint textPaint = new Paint(Color.RED); 
    textPaint.setTextSize(16); 
    textPaint.setStrokeWidth(30); 
    textPaint.setTextAlign(Paint.Align.CENTER); 
    textPaint.setStyle(Style.FILL); 
    canvas.drawText("HelloWorld", 0, 400,textPaint); 
} 

任何幫助表示讚賞!

P.s.我也與此代碼試了一下:

Paint textPaint = new Paint(Color.RED); 
    canvas.drawText("HelloWorld", 0, 400,textPaint); 

截圖: enter image description here

enter image description here

+1

如果您對於代碼「不工作」的具體方式,您更有可能獲得幫助。告訴我們你的期望和實際得到的結果。由於這涉及圖形,截圖可能有助於準確解釋發生了什麼問題。 – 2014-12-19 03:00:06

+0

好吧會發佈一個屏幕截圖,但總結文本是不呈現,其他所有。 @JeffreyBosboom – oorosco 2014-12-19 03:00:55

回答

1

Paint構造函數的參數,你用 - 即Paint(int) - 是標誌,如ANTI_ALIAS_FLAG,而不是顏色值。更改您的實例化和初始化,如下所示:

Paint textPaint = new Paint(); 
textPaint.setColor(Color.RED); 
+1

Omg,我不能相信我錯過了這件事,我是啞巴= _ = 。謝謝! – oorosco 2014-12-19 05:40:20

相關問題