How to align text to relative shape automatically ?

Hi,

Is there a way I can align text to be in the middle of a circle automatically. the text will contain number and the number can be 1 figure, 2 figures or 3 figures.

[lua]

local circle1 = display.newCircle( 100, 100, 60 )
local circle2 = display.newCircle( 300, 100, 60 )

circle1.alpha = 0.5
circle2.alpha = 0.5

local num1 = display.newText( “1”, 130, 130, native.systemFont, 40 )
local num1 = display.newText( “12”, 330, 130, native.systemFont, 40 )

[/lua]

There was a corona tutorial/blog post about multiline text - as part of that tut - it had an options table which had a variable for alignment - left, centre , etc… 

That might give you the answer or lead you require.

T.

Like this, or did I not understand your question?:

local circ = display.newCircle( 50, 50, 25 ) local txt = display.newText( "A", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 1,0,0 ) local circ = display.newCircle( 150, 150, 25 ) local txt = display.newText( "B", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,1,0 ) local circ = display.newCircle( 50, 250, 25 ) local txt = display.newText( "C", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,0,1 ) local circ = display.newCircle( 150, 350, 25 ) local txt = display.newText( "D", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,0,0 ) 

align2circle.jpg

Excellent, thanks for your the time to do the example and show it here., I appreciate it…

Just one more question… I noticed you were using one variable name for the circle and the text… is it fine to do this way or is it better to give different name.

Regards

Abdulaziz

There was a corona tutorial/blog post about multiline text - as part of that tut - it had an options table which had a variable for alignment - left, centre , etc… 

That might give you the answer or lead you require.

T.

Like this, or did I not understand your question?:

local circ = display.newCircle( 50, 50, 25 ) local txt = display.newText( "A", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 1,0,0 ) local circ = display.newCircle( 150, 150, 25 ) local txt = display.newText( "B", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,1,0 ) local circ = display.newCircle( 50, 250, 25 ) local txt = display.newText( "C", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,0,1 ) local circ = display.newCircle( 150, 350, 25 ) local txt = display.newText( "D", circ.x, circ.y, system.nativeFont, 20 ) txt:setFillColor( 0,0,0 ) 

align2circle.jpg

Excellent, thanks for your the time to do the example and show it here., I appreciate it…

Just one more question… I noticed you were using one variable name for the circle and the text… is it fine to do this way or is it better to give different name.

Regards

Abdulaziz