你好,貌似是我创建的那个类的node在lua中通过父节点的getChidren方法取不到该node,得到的数组长度为0,其父节点调用getChildrenCount获得数量是1,对应的C++对象在,你知道这是什么原因造成的吗?是不是绑定的时候少处理了?
相关代码和调试输出的log再帖一下看看呢
local rect = cc.rect(100, 100,200, 200)
local clipenode = cc.ClippingRegionNode:create(rect)
local cnode = cc.ScrollViewContent:create() --自定义类,继承自node 绑定代码如上
cnode:setPosition(cc.p(0, 0))
cnode:addTo(clipenode)
print("-------count-------",#clipenode:getChildren(),clipenode:getChildren())
print("+++++++count+++++++",clipenode:getChildrenCount())
打印结果:
-------count------- 0 table
+++++++count+++++++ 1
疑惑:getChildren()得到的应该是个数组吧?
麻烦你了!
呵呵,返回的是一个table。你dump一下它看看?
改成这样后:
print("-------count-------",#clipenode:getChildren(),clipenode:getChildren())
print("+++++++count+++++++",clipenode:getChildrenCount())
for k, v in pairs(clipenode:getChildren()) do
print("++++++key,value++++++",k,v)
end
打印结果:没变,for循环内的语句没打印
-------count------- 0 table
+++++++count+++++++ 1
下面是dump的结果,一样
dump from: [string “E:/work/quick-cocos2d-x-3.2rc1/project/helloworld/src/app/sc
enes/MainScene.lua”]:18: in function ‘ctor’
- 0 = “-------count-------”
dump from: [string “E:/work/quick-cocos2d-x-3.2rc1/project/helloworld/src/app/sc
enes/MainScene.lua”]:19: in function ‘ctor’ - 1 = “+++++++count+++++++”
v3遍历children不是用ipairs就可以吗?
不应该啊,如果你使用cc.Node:create(),是什么样的结果呢?
这是display.newNode()创建的node
local cnode = display.newNode()
– local cnode = cc.ScrollViewContent:create()
cnode:setPosition(cc.p(0, 0))
cnode:addTo(clipenode)
print("-------count-------",#clipenode:getChildren(),clipenode:getChildren())
print("+++++++count+++++++",clipenode:getChildrenCount())
for k, v in pairs(clipenode:getChildren()) do
print("++++++key,value++++++",k,v)
end
打印结果:
-------count------- 1 table
+++++++count+++++++ 1
++++++key,value++++++ 1 userdata
查了一下,cocos 3.x之后返回对象数组有一些特殊处理,用2.x的tolua脚本方式绑定支持得还不好,只有等后面再修改一下了。
在你13楼的代码后面,加上这几句吧:
tolua_endmodule(tolua_S);
std::string typeName = typeid(ScrollViewContent).name();
g_luaType = "ScrollViewContent";
g_typeCast"ScrollViewContent"] = "ScrollViewContent";
return 1;
太感谢了,在VS里面跟了半天刚发现问题在type那一块,模棱两可,不过不确定。也不知道咋解决,及时雨啊!多谢,试了下,可以了!多谢了!
MARK~\
