Hi, how can I wrap text after a paragraph?
EXAMPLE:
local text = display.newText( "AAAAAAAA. BBBBBBBBBBBBBBBBBBBBBBBBBBBB.", 0, 0, "Imaki", 15)
RESULT:
AAAAAAAA.
BBBBBBBBBBBBBBBBBBBBBBBBBBBB.
How can I do it?
Hi, how can I wrap text after a paragraph?
EXAMPLE:
local text = display.newText( "AAAAAAAA. BBBBBBBBBBBBBBBBBBBBBBBBBBBB.", 0, 0, "Imaki", 15)
RESULT:
AAAAAAAA.
BBBBBBBBBBBBBBBBBBBBBBBBBBBB.
How can I do it?
Normally to get display.newText() to support multiple lines you have to provide a width and optional height:
myText = display.newText(“some really long string of text”, X, Y, width, height, “Font”, fontSize)
Where X, Y are where you want the string centered on the screen.
width is the width of the box you want the string to fit in. It will wrap once the string hits that width, but on whole words only, so in your example, because “BBBBBBBBBBBBBBBBBBBBBBBBBBBB” is so long it’s likely going to wrap just like you have it. If you provide a height, the box will cut off any extra text that becomes too long to fit in the box. If your height is 0, it will show the whole text regardless of the length.
This is the old school method of display,newText. The newer version uses an table of information to provide these parameters, which includes an alignment option (defaults to “left”) for aligning each line in the box. See: http://docs.coronalabs.com/api/library/display/newText.html#syntax for more information.
Rob
Sorry, I try to explain it better. I have already set the width parameter and the text wrap exactly, but I also want to wrap text at the end of the sentences. Look at the photo for an example.
I’m sorry I still don’t understand your problem exactly. The example code you listed in the top post is in “single line” mode. Can you post the exact code you are using. Is the screen shot above what you want or what you are getting? If it’s what you are getting, what is wrong with it?
Rob
The screenschot is what I want. here the code:
local testo = "Il tuo scopo è indovinare la risposta più probabile data ad una domanda già sottoposta ad un campione di 100 persone. Per ogni risposta indovinata vengono dati punti pari alla percentuale di persone intervistate che hanno risposto al sondaggio in tal modo sommati al tempo rimanente. Nella prima manche avrai 7 possibili risposte, nella seconda 6, nella terza 5, nella quarta 4. Nella quinta macnhe avrai due domande e 1 possibile risposta per ciascuna (la più gettonata). Per le prime quattro manche si possono commettere tre errori; nella quinta solo uno. Ogni errore sottrae 10 punti. Nelle prime quattro manche hai 30 secondi, mentre nella quinta hai 60 secondi per tentativo. WeGuess provvede a inviare il tuo punteggio a Google Play Games automaticamente. Cosa aspetti? Sfida subito i tuoi amici a WeGuess!" tGioco = display.newText(screenGroup, testo, 0, 0, 300, 0, "Imaki", 15) tGioco:setReferencePoint(display.CenterReferencePoint) tGioco.x = display.contentCenterX
How can i wrap text as the screenshot? How can i wrap text after the first sentence, for example?
Actually this is the result:
Okay, I think I have it now. You want to add paragraph breaks (the blank lines between paragraphs). Simply add:
“\n\n”
at the point where you want the paragraph break. This will insert two “newlines”, one ends the paragraph, the second puts a blank line between them.
Rob
Oh thank you! You really help me!
Normally to get display.newText() to support multiple lines you have to provide a width and optional height:
myText = display.newText(“some really long string of text”, X, Y, width, height, “Font”, fontSize)
Where X, Y are where you want the string centered on the screen.
width is the width of the box you want the string to fit in. It will wrap once the string hits that width, but on whole words only, so in your example, because “BBBBBBBBBBBBBBBBBBBBBBBBBBBB” is so long it’s likely going to wrap just like you have it. If you provide a height, the box will cut off any extra text that becomes too long to fit in the box. If your height is 0, it will show the whole text regardless of the length.
This is the old school method of display,newText. The newer version uses an table of information to provide these parameters, which includes an alignment option (defaults to “left”) for aligning each line in the box. See: http://docs.coronalabs.com/api/library/display/newText.html#syntax for more information.
Rob
Sorry, I try to explain it better. I have already set the width parameter and the text wrap exactly, but I also want to wrap text at the end of the sentences. Look at the photo for an example.
I’m sorry I still don’t understand your problem exactly. The example code you listed in the top post is in “single line” mode. Can you post the exact code you are using. Is the screen shot above what you want or what you are getting? If it’s what you are getting, what is wrong with it?
Rob
The screenschot is what I want. here the code:
local testo = "Il tuo scopo è indovinare la risposta più probabile data ad una domanda già sottoposta ad un campione di 100 persone. Per ogni risposta indovinata vengono dati punti pari alla percentuale di persone intervistate che hanno risposto al sondaggio in tal modo sommati al tempo rimanente. Nella prima manche avrai 7 possibili risposte, nella seconda 6, nella terza 5, nella quarta 4. Nella quinta macnhe avrai due domande e 1 possibile risposta per ciascuna (la più gettonata). Per le prime quattro manche si possono commettere tre errori; nella quinta solo uno. Ogni errore sottrae 10 punti. Nelle prime quattro manche hai 30 secondi, mentre nella quinta hai 60 secondi per tentativo. WeGuess provvede a inviare il tuo punteggio a Google Play Games automaticamente. Cosa aspetti? Sfida subito i tuoi amici a WeGuess!" tGioco = display.newText(screenGroup, testo, 0, 0, 300, 0, "Imaki", 15) tGioco:setReferencePoint(display.CenterReferencePoint) tGioco.x = display.contentCenterX
How can i wrap text as the screenshot? How can i wrap text after the first sentence, for example?
Actually this is the result:
Okay, I think I have it now. You want to add paragraph breaks (the blank lines between paragraphs). Simply add:
“\n\n”
at the point where you want the paragraph break. This will insert two “newlines”, one ends the paragraph, the second puts a blank line between them.
Rob
Oh thank you! You really help me!