Width and Height in Texts

Hey guys,

So I have these texts in an array and randomly selected:[code]
array = {}
local i = 1
array[i]= display.newText(“I want these texts to be divided into lines!!”, 0, 0, 0, 0, native.systemFont, 15*2);array[i].alpha=0;i=i+1
array[i]= display.newText(“I want these texts to be divided into lines!!”, 0, 0, 0, 0, native.systemFont, 15*2);array[i].alpha=0;i=i+1
array[i]= display.newText(“I want these texts to be divided into lines!!”, 0, 0, 0, 0, native.systemFont, 15*2);array[i].alpha=0;i=i+1
array[i]= display.newText(“I want these texts to be divided into lines!!”, 0, 0, 0, 0, native.systemFont, 15*2);array[i].alpha=0;i=i+1

function selectext()
local randomtext = math.random(1,#array)

–1 to highest index in the table
array[randomtext].xScale = 0.5
array[randomtext].yScale = 0.5
array[randomtext].alpha=1
array[randomtext].x = _W/2
array[randomtext].y = _H/2 - 30
array[randomtext]:setReferencePoint(display.CenterReferencePoint)
array[randomtext].width = 500
array[randomtext].height = 0
end
selectext()[/code]

However, like this, my width is right, but instead of multi-lining, it shrinks my text into one line, with the size considerably smaller.

Any thoughts?
Thanks
[import]uid: 95495 topic_id: 20786 reply_id: 320786[/import]

Setting the width property after the fact alters the width of the whole display object, not the width of the text’s bounding box.

Thus, the squishing.

If you set the width ahead of time, when you call the newText function in the array - it will work as you intend it to.

i.e:

array[i]= display.newText("I want these texts to be divided into lines!!", 0, 0, 500, 0, native.systemFont, 15\*2)

I’m not sure if you can alter the bounding box after it has been declared.

hope this helps?

Joe [import]uid: 8444 topic_id: 20786 reply_id: 81735[/import]

Hey, I tried that too!

But it just appears as no width has been set…is there any other way to break the text into lines? [import]uid: 95495 topic_id: 20786 reply_id: 81743[/import]

Hmmm. I don’t know why it wasn’t breaking into lines for you?

I pasted your code into my file and it worked fine.

That is the only native way that I know to do multiline text.

I also use the TextWrapper code from the code exchange which lets you do some other stuff like multiline centered text. You might want to give that a try.

http://developer.anscamobile.com/code/wrap-text [import]uid: 8444 topic_id: 20786 reply_id: 81749[/import]

It worked! Thanks…
Any idea on how to centralize or justify the texts with wrapping?? [import]uid: 95495 topic_id: 20786 reply_id: 81761[/import]

Not natively unfortunately, hopefully they will add it in.

I needed centered, multiline text in my game so I went with those Text Wrap functions that I linked to above. Works great! [import]uid: 8444 topic_id: 20786 reply_id: 81762[/import]

Yeah, I meant Text Wrap in my previous post!

But I can’t figure out where to set it centered in that huge code posted there! [import]uid: 95495 topic_id: 20786 reply_id: 81773[/import]