1
votes

Using Corona SDK for building iOS app, I want to align text to center, I read some discussion this can be done by 'setReferencePoint', I tried to make it, but failed, anybody can show me an example??

Here is my code:

message = display.newText("TEXT HERE!! TEXT HERE!! TEXT HERE!! TEXT HERE!! TEXT HERE!!",  140, 120, 240, 400, native.systemFontBold, 18 )

message:setReferencePoint(display.CenterReferencePoint)
message.x = 200
message:setTextColor(0, 126, 255)

g:insert(message)

Thanks!!

2

2 Answers

0
votes

In Corona SDK, by default the reference point is display.CenterReferencePoint unless you are providing the X, Y values as parameters.

In your case - I think you should use -

message.x = X ---- X = center of object message.y = Y ---- Y = center of object

0
votes

you must use like this

skorX = cx - 10
nilaiSkorr = nilaiSkor + 0
if nilaiSkorr >= 10 then
    skorX = cx - 20
elseif nilaiSkorr >= 100 then
    skorX = cx - 30
end

local t = display.newText(nilaiSkor, skorX, cy + 3, native.systemFontBold, 30 )
t:setReferencePoint(display.CenterReferencePoint)