2014-12-19 122 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

相关问题