Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline character in a text using canvas.drawText

I'm doing an Android Game, and I'm using a function like this to show texts on the device screen:

public void drawString(String text, int x, int y, Paint paint) {
    canvas.drawText(text, x, y, paint);

}

And I try to show the following message:

g.drawString("Player: " + playerString+ " :\n" + messageString,SCREENWIDTH / 2, SCREENHEIGHT / 2, paint);

However instead of a newline (\n) I get a strange character (a square).

Anyone can help me?

Thanks

like image 342
user2204353 Avatar asked Sep 12 '25 11:09

user2204353


1 Answers

Instead of drawString call drawText and for break lines call drawText twice with Y offset.

look here for example Draw multi-line text to Canvas

like image 122
Elior Avatar answered Sep 15 '25 01:09

Elior