Cocos2d-x结构学习(一)CCObject、CCCopying、CCZone

前端之家收集整理的这篇文章主要介绍了Cocos2d-x结构学习(一)CCObject、CCCopying、CCZone前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、CCZone类:保存了CCObject的指针。

class CC_DLL CCZone
{
public:
    CCZone(CCObject *pObject = NULL);


public:
    CCObject *m_pCopyObject;
};

CC_DLL的定义为(动态链接库相关):

#if defined(_USRDLL)
    #define CC_DLL     __declspec(dllexport)
#else         /* use a DLL library */
    #define CC_DLL     __declspec(dllimport)
#endif
2、CCCopying:拷贝CCZone类里的CCObject对象,仅是指针
class CC_DLL CCCopying
{
public:
    virtual CCObject* copyWithZone(CCZone* pZone);
};

3、CCObject类:继承自CCCopying类,各成员如下:
class CC_DLL CCObject : public CCCopying
{
public:
    unsigned int        m_uID;             //对象ID,<span style="font-family: Arial,Helvetica,sans-serif;">CCScriptSupport需要公共的ID。</span>
    int                 m_nLuaID;          //LUA引用ID。
protected:
    unsigned int        m_uReference;        //引用计数
    unsigned int        m_uAutoReleaseCount;  //自动释放计数
public:
    CCObject(void);
    virtual ~CCObject(void);
    
    void release(void);
    void retain(void);
    CCObject* autorelease(void);
    CCObject* copy(void);
    bool isSingleReference(void) const;
    unsigned int retainCount(void) const;
    virtual bool isEqual(const CCObject* pObject);

    virtual void acceptVisitor(CCDataVisitor &visitor);
    virtual void update(float dt) {CC_UNUSED_PARAM(dt);};
    friend class CCAutoreleasePool;
};
CCObject定义的成员函数指针:
typedef void (CCObject::*SEL_SCHEDULE)(float);
typedef void (CCObject::*SEL_CallFunc)();
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
typedef void (CCObject::*SEL_CallFuncND)(CCNode*,void*);
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
typedef void (CCObject::*SEL_MenuHandler)(CCObject*);
typedef void (CCObject::*SEL_EventHandler)(CCEvent*);
typedef int (CCObject::*SEL_Compare)(CCObject*);
CCObject相关的函数宏:
#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)
#define callfunc_selector(_SELECTOR) (SEL_CallFunc)(&_SELECTOR)
#define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR)
#define callfuncND_selector(_SELECTOR) (SEL_CallFuncND)(&_SELECTOR)
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
#define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR)
#define compare_selector(_SELECTOR) (SEL_Compare)(&_SELECTOR)

猜你在找的Cocos2d-x相关文章