This site requires JavaScript, please enable it in your browser!
Greenfoot back
itssemu
itssemu wrote ...

2018/3/9

How do I add text over multiple lines?

itssemu itssemu

2018/3/9

#
Hi there again, would somebody please be able to guide me as to how to get an actor that has an image as some text to print over more than one line? it currently looks like this
1
2
3
4
public void act()
{
    setImage(new GreenfootImage("Press 'r' to restart" + /**I want to seperate the line here*/"Press 'p' to pause the game" , 30, Color.WHITE, new Color(0,0,0,0)));
}
and i would like the output to be: Press 'r' to restart Press'p' to pause the game
Super_Hippo Super_Hippo

2018/3/9

#
You can use \n to get into a new line. If this causes formatting issues, you could create one image for each line and draw all of them on one image.
Yehuda Yehuda

2018/3/9

#
This can be line 3:
1
setImage(new GreenfootImage("Press 'r' to restart\nPress 'p' to pause the game", 30, Color.WHITE, new Color(0, 0, 0, 0)));
(Written example of Hippo's reply.)
itssemu itssemu

2018/3/9

#
ohhhhh i thought the \n couldn't be a part of the string because it would just print it
Yehuda Yehuda

2018/3/11

#
You cannot put "\" in a String without one of the characters on the bottom of this page following it.
You need to login to post a reply.