It looks like you're new here. If you want to get involved, click one of these buttons!
local layout_params = { flags = FontBase.TLF_CENTER|FontBase.TLF_VCENTER } --local layout_params = { flags = FontBase.TLF_CENTER|FontBase.TLF_REF_MIDDLE } local text = TextField.new(global.fredoka_120,"123312") text:setTextColor(0xFFFFF) self:addChild(text) text:setPosition(CX, CY) self:addChild(text) text:setText("123312") text:setLayout(layout_params) |
Comments
FontBase.TLF_CENTER works without providing the width so I just think FontBase.TLF_VCENTER will work with the single line too.
Anyway, I can handle the center by set flag FontBase.TLF_REF_MIDDLE or calculate by add getHeight() * 0.5 to the desired Y pos
With FontBase.TLF_REF_TOP we will turn textfield to top left base point and then FontBase.TLF_CENTER|FontBase.TLF_VCENTER will equals setAnchorPosition 0.5, 0.5
So the hacky way is
local layout_params = { flags = FontBase.TLF_CENTER|FontBase.TLF_VCENTER|FontBase.TLF_REF_TOP}
text:setLayout(layout_params)
text:setPosition(px, py)
And then (px, py) is always the center of the text
Thank for your detail explain!
Likes: antix