textalign center

OK. I have this in my code.

local multiText = display.newText( “Very long long long long long long text for my community.”, halfW/2, halfH+50, 400, 200, “Georgia Italic”, 24 )
multiText:setTextColor( 255,255,255, 202 )

The text is alignel left. How can I center this text without help of other libraries like crawlspaceLib, which brokes my visuals [import]uid: 8303 topic_id: 26024 reply_id: 326024[/import]

Depends what you mean.

  1. Initially, display.newText() prints text from display.TopLeftReferencePoint. (imagine all of your text is in an invisible rectangle. The snap point is in the top left.)

  2. Immediately after, the reference point (snap point) is moved to the center of the rectangle. (display.CenterReferencePoint)

So if you want to center the text, what you should be doing is:

local multiText = display.newText("whatevs", 0, 0, 400, 200, "Georgia Italic", 24) multiText:setReferencePoint(display.CenterReferencePoint) -- apparently not required, but it's good practice if you want to know reference points at a glance. multiText.x, multiText.y = halfW/2, halfH+50

[import]uid: 41884 topic_id: 26024 reply_id: 105296[/import]

Thanks
richard9

“you are my man”!

[import]uid: 8303 topic_id: 26024 reply_id: 105302[/import]

er…it’s “the man”. very awkward sentence otherwise [import]uid: 41884 topic_id: 26024 reply_id: 105304[/import]

Hi, I was to quick, it doesnt work, the text is still left aligned

like this:

some text some text some text
some text some
some [import]uid: 8303 topic_id: 26024 reply_id: 105306[/import]

Hmm. You’re right. I think somebody else posted about this too. It seems that when you use multiline text via display.newText(), you are limited to left alignment. This is a bug. I just filed it. [import]uid: 41884 topic_id: 26024 reply_id: 105313[/import]

I filed it too, weeks ago, still no reply :frowning:

Peach, can you check out if this can be fixed anytime soon?

Case 14250

If using multiline text, lines within the text are not centered if using display.CenterReferencePoint

Also check:
http://developer.anscamobile.com/forum/2012/04/12/how-align-multiline-text

Also, Fogbugz at bugs.anscamobile.com seems to be down since a while?

[import]uid: 50459 topic_id: 26024 reply_id: 108828[/import]