lua设置label的垂直居中报错

label = Label:create()

label:setTextVerticalAlignment(kCCVerticalTextAlignmentCenter)

错误提示:error in function ‘setTextVerticalAlignment’.
argument #2 is ‘number’; ‘CCVerticalTextAlignment’ expected.

很明显参数肯定是CCVerticalTextAlignment

这个主要是cocostudio里面没有包含cocos2d-x的ccTypes.pkg所以导致找不到这个枚举而导致的生成的区别

你可以在cpp里面

(tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,“CCVerticalTextAlignment”,0,&tolua_err))
改成
!tolua_isnumber(tolua_S,2,0,&tolua_err)

((CCVerticalTextAlignment) tolua_tousertype(tolua_S,2,0))

改成

((CCVerticalTextAlignment) (int) tolua_tonumber(tolua_S,2,0))

如果你经常修改pkg的话,那也可以在basic_cocostudio.lua添加

replace((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"
CCVerticalTextAlignment ",0,&tolua_err))]],!tolua_isnumber(tolua_S,2,0,&tolua_err)]])

replace(
CCVerticalTextAlignment alignment = *((
CCVerticalTextAlignment *) tolua_tousertype(tolua_S,2,0));]],
CCVerticalTextAlignment alignment = ((
CCVerticalTextAlignment ) (int) tolua_tonumber(tolua_S,2,0));]])

就是类似里面原本的CCTextAlignment的替换

谢谢,早就已经替换了,当时就是很奇怪,你们的水平居中和垂直居中的tolua的解析代码不一样,然后自己改了