framework里
ui.lua
https://github.com/chukong/quick-cocos2d-x/blob/master/framework/ui.lua
if label then
label:setColor(color)
function label:realign(x, y)
if textAlign == ui.TEXT_ALIGN_LEFT then
label:setPosition(math.round(x +label:getContentSize().width / 2), y)
elseif textAlign == ui.TEXT_ALIGN_RIGHT then
label:setPosition(x - math.round(label:getContentSize().width / 2), y)
else
label:setPosition(x, y)
end
end
if x and y then label:realign(x, y) end
end
if textAlign == ui.TEXT_ALIGN_LEFT then
此时 加上了宽度的一半
我之前是 as3 开发者
left align时 左对齐 应该是 靠左 感觉不应该 加宽度的一半
猜测之前 是默认设置
local textAlign
= params.align
or ui.TEXT_ALIGN_LEFT
这句和 默认的 anchorPoint设置有些出入
调整正常的效果 就需要 统一 默认 anchorPoint center_middle 和 TEXT_ALIGN_LEFT
if TEXT_ALIGN_LEFT 就写了 中中的逻辑
--------------之前的bug-------------------
local name = ui.newTTFLabel({
text = “名字”,
size = 18,
color = ccc3(121, 50, 27),
x = 100,
y = 200
})
name:align(display.LEFT_TOP)
name:addTo(self)
设置了 align(display.LEFT_TOP) 后
输入文字越长 位置向右偏移 越多
具体表现和
display.CENTER_TOP 一样
设置 center_top 变右对齐了
rignt_top 又显示为左对齐了
ccsprit align 工作正常