用Setreferencepoint来将Corona SDK中的文本居中对齐...

使用 Corona SDK 构建 iOS 应用程序时,我想将文本对齐到中心,我阅读了一些讨论,这可以通过 'setReferencePoint' 完成,我尝试了它,但失败了,有人可以给我一个示例吗?

这是我的代码:

`` ` 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)

`` `

谢谢!!

点赞
用户889843
用户889843

在 Corona SDK 中,默认的参考点是 display.CenterReferencePoint,除非你将 X 和 Y 值作为参数提供。

在你的情况下 - 我认为你应该使用 -

message.x = X ---- X = 对象中心
message.y = Y ---- Y = 对象中心
2013-04-09 08:04:46
用户3718787
用户3718787
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)
skorX = cx - 10
nilaiSkorr = nilaiSkor + 0
如果 nilaiSkorr 大于等于 10,则
    skorX = cx - 20
否则如果 nilaiSkorr 大于等于 100,则
    skorX = cx - 30
结束

local t = display.newText(nilaiSkor, skorX, cy + 3, native.systemFontBold, 30 )
t:setReferencePoint(display.CenterReferencePoint)
2015-07-02 08:45:17