v2.2.2 cocostudio的lua绑定

      
    local node = SceneReader:sharedSceneReader():createNodeWithSceneFile("scenetest/LoadSceneEdtiorFileTest/FishJoy2.json") 

    local star = node:getChildByTag(10004)
    local star_button = star:getComponent("GUIComponent")

我在TestLua里的CocoStudioSceneTest.lua里添加了后面两句代码,出现了这样的错误:

Cocos2d:  :22: attempt to call method 'getComponent' (a nil value)

我到LuaCocos2d.cpp里去看,发现并没有把CCNode里的getComponent绑定到lua中,但是在CCNode.h中又没有针对getComponent的@lua NA的注释,这是怎么回事呢,是我没有用对还是引擎的缺陷呢

嗯,这个确实是没有添加。如果要加这个接口的支持,还需要将CCComponent导出到pkg。谢谢反馈,下个版本会更新这个绑定。

还要到下一版才修啊~? 这个bug直接导致用lua的项目cocostudio不能用了~~

很多方法可以代替,几乎完全不影响啊

目前你可以这样做:找到tolua++的目录

1.新建CCComponent.pkg文件,然后把
class CCComponent : public CCObject
{
virtual ~CCComponent(void);
virtual bool init();
virtual void update(float delta);
virtual bool serialize(void* r);
virtual bool isEnabled() const;
virtual void setEnabled(bool b);
static CCComponent* create(void);
const char* getName() const;
void setName(const char *pName);
void setOwner(CCNode pOwner);
CCNode
getOwner() const;
};

这一段拷进去。

2.找到CCNode.pkg 添加
CCComponent* getComponent(const char *pName);

3.然后在basic.lua里面将
“CCComponent”
加到CCObjectTypes这个table的最后面

4.运行build.sh或者build.bat

就可以了

什么替代方案?举个栗子。
componentContainer是protected。

什么替代方案?举个栗子。
componentContainer是protected。