经常有一些数据需要跟某个节点相关联,存放在Node中的m_pUserObject变量即可。
CCObject *m_pUserObject; ///< A user assigned CCObject
virtual CCObject* getUserObject();
virtual void setUserObject(CCObject *pUserObject);
lua中的使用:
存:
local itemPic = CCSprite:create(picName)
itemPic:setUserObject(CCString:create(itemId))
取:
local touchObj = tolua.cast(itemPic,"CCNode"):getUserObject()
local itemId = tolua.cast(touchObj,"CCString"):getCString()