1 CCNode是cocos2d-x中一個很重要的類,CCNode是場景、層、菜單、精靈等的父類。而我們在使用cocos2d-x時,接觸最多的就是場景、層、菜單、精靈等。所以有必要先弄懂CCNode類
2 CCObject類是cocos2d-x中所有對象的基類,CCObject封裝了對象的引用計數和自動釋放功能,下面是類圖
3 因爲場景、層、精靈、菜菜單是CCNode的子類,所以在使用它們時,有些方法來自CCNode,下面解釋了CCNode中常用的方法
[cpp]
//初始化CCNode
bool init();
//生成CCNode對象
CCNode * create(void);
//獲取描述字符串 便於調試
const char* description(void);
//設置節點Z軸順序 當有多個節點在Z軸顯示時 引擎會根據它們Z軸的大小決定繪製順序 Z軸大的會覆蓋Z軸小的
void setZOrder(int zOrder);
void _setZOrder(int z);
//獲取節點Z軸順序
int getZOrder();
//設置OpenGL Z軸頂點
void setVertexZ(float vertexZ);
//獲取OpenGL Z軸頂點
float getVertexZ();
//設置節點X軸比例因子
void setScaleX(float fScaleX);
//獲取節點X軸比例因子
float getScaleX();
//設置節點Y軸比例因子
void setScaleY(float fScaleY);
//獲取節點Y軸比例因子
float getScaleY();
//設置節點比例因子 同時設置X軸、Y軸
void setScale(float scale);
//獲取節點比例因子 必須X軸、Y軸比例因子相等
float getScale();
//設置節點(x, y)在OpenGL中的座標
void setPosition(const CCPoint &position);
//獲取節點(x, y)在OpenGL中的座標
const CCPoint& getPosition();
//設置節點(x, y)在OpenGL中的座標
void setPosition(float x, float y);
//獲取節點(x, y)在OpenGL中的座標
void getPosition(float* x, float* y);
//設置節點在OpenGL中的X座標
void setPositionX(float x);
//獲取節點在OpenGL中的X座標
float getPositionX(void);
//設置節點在OpenGL中的Y座標
void setPositionY(float y);
//獲取節點在OpenGL中的Y座標
float getPositionY(void);
//設置X軸的傾斜角度
void setSkewX(float fSkewX);
//獲取X軸的傾斜角度
float getSkewX();
//設置Y軸的傾斜角度
void setSkewY(float fSkewY);
//獲取Y軸的傾斜角度
float getSkewY();
//設置節點錨點的位置
void setAnchorPoint(const CCPoint& anchorPoint);
//獲取節點錨點的位置
const CCPoint& getAnchorPoint();
//設置節點的尺寸
void setContentSize(const CCSize& contentSize);
//獲取節點的尺寸
const CCSize& getContentSize();
//設置節點是否可見
void setVisible(bool visible);
//獲取節點是否可見
bool isVisible();
//設置節點自轉角度
void setRotation(float fRotation);
//獲取節點自轉角度
float getRotation();
//zOrder 當有多個節點在Z軸顯示時 引擎會根據它們Z軸的大小決定繪製順序 Z軸大的會覆蓋Z軸小的
//添加子節點 zOrder默認爲0
void addChild(CCNode * child);
//添加子節點
void addChild(CCNode * child, int zOrder);
//添加子節點 指定節點zOrder和節點tag
void addChild(CCNode* child, int zOrder, int tag);
//通過tag名稱獲取節點
CCNode * getChildByTag(int tag);
//獲取所有子節點
CCArray* getChildren();
//獲取子節點數目
unsigned int getChildrenCount(void);
//設置子節點的父節點
void setParent(CCNode* parent);
//獲取子節點的父節點
CCNode* getParent();
//從父節點中刪除當前子節點
void removeFromParent();
//從父節點中刪除當前子節點 如果Cleanup爲true則刪除當前節點的所有動作及回調函數
void removeFromParentAndCleanup(bool cleanup);
//從父節點中刪除當前子節點 如果Cleanup爲true則刪除當前節點的所有動作
void removeChild(CCNode* child);
//從父節點中刪除當前子節點 並指定Cleanup
void removeChild(CCNode* child, bool cleanup);
//通過tag名稱移除節點
void removeChildByTag(int tag);
//通過tag名稱移除節點並指定Cleanup
void removeChildByTag(int tag, bool cleanup);
//移除所有子節點
void removeAllChildren();
//移除所有子節點 並指定Cleanup
void removeAllChildrenWithCleanup(bool cleanup);
//重新設定節點的zOrder
void reorderChild(CCNode * child, int zOrder);
//重新排序所有子節點
void sortAllChildren();
//獲取節點的tag名稱
int getTag();
//設置節點的tag名稱
void setTag(int nTag);
//獲取節點的CCCamera攝像機 cocos2d-x是通過3D方式繪製2D效果
CCCamera* getCamera();
//判斷當前節點是否在運行
bool isRunning();
//節點開始進入舞臺時的回調事件
void onEnter();
//節點進入舞臺時的回調事件
void onEnterTransitionDidFinish();
//節點離開舞臺時的回調事件
void onExit();
//停止所有運行的動作和回調函數
void cleanup(void);
//繪製節點
void draw(void);
//遞歸visit子節點並重繪
void visit(void);
//返回節點對象的矩形框(由座標寬高組成)
CCRect boundingBox(void);
//設置CCActionManager對象被所有動作使用
void setActionManager(CCActionManager* actionManager);
//獲取被所有動作使用的CCActionManger
CCActionManager* getActionManager();
//執行動作
CCAction* runAction(CCAction* action);
//停止動作
stopAction(CCAction* action);
//停止所有動作
void stopAllActions(void);
//通過tag名稱獲取動作
CCAction* getActionByTag(int tag);
//獲取正在運行的動作數量
unsigned int numberOfRunningActions(void);
//定義一個定時器
void schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay);
//定義一個定時器
void schedule(SEL_SCHEDULE selector, float interval);
//取消一個定時器
void unschedule(SEL_SCHEDULE selector);
//取消所有定時器
void unscheduleAllSelectors(void);
//暫停所有定時器和動作
void pauseSchedulerAndActions(void);
//恢復所有定時器和動作
void resumeSchedulerAndActions(void);
//初始化CCNode
bool init();
//生成CCNode對象
CCNode * create(void);
//獲取描述字符串 便於調試
const char* description(void);
//設置節點Z軸順序 當有多個節點在Z軸顯示時 引擎會根據它們Z軸的大小決定繪製順序 Z軸大的會覆蓋Z軸小的
void setZOrder(int zOrder);
void _setZOrder(int z);
//獲取節點Z軸順序
int getZOrder();
//設置OpenGL Z軸頂點
void setVertexZ(float vertexZ);
//獲取OpenGL Z軸頂點
float getVertexZ();
//設置節點X軸比例因子
void setScaleX(float fScaleX);
//獲取節點X軸比例因子
float getScaleX();
//設置節點Y軸比例因子
void setScaleY(float fScaleY);
//獲取節點Y軸比例因子
float getScaleY();
//設置節點比例因子 同時設置X軸、Y軸
void setScale(float scale);
//獲取節點比例因子 必須X軸、Y軸比例因子相等
float getScale();
//設置節點(x, y)在OpenGL中的座標
void setPosition(const CCPoint &position);
//獲取節點(x, y)在OpenGL中的座標
const CCPoint& getPosition();
//設置節點(x, y)在OpenGL中的座標
void setPosition(float x, float y);
//獲取節點(x, y)在OpenGL中的座標
void getPosition(float* x, float* y);
//設置節點在OpenGL中的X座標
void setPositionX(float x);
//獲取節點在OpenGL中的X座標
float getPositionX(void);
//設置節點在OpenGL中的Y座標
void setPositionY(float y);
//獲取節點在OpenGL中的Y座標
float getPositionY(void);
//設置X軸的傾斜角度
void setSkewX(float fSkewX);
//獲取X軸的傾斜角度
float getSkewX();
//設置Y軸的傾斜角度
void setSkewY(float fSkewY);
//獲取Y軸的傾斜角度
float getSkewY();
//設置節點錨點的位置
void setAnchorPoint(const CCPoint& anchorPoint);
//獲取節點錨點的位置
const CCPoint& getAnchorPoint();
//設置節點的尺寸
void setContentSize(const CCSize& contentSize);
//獲取節點的尺寸
const CCSize& getContentSize();
//設置節點是否可見
void setVisible(bool visible);
//獲取節點是否可見
bool isVisible();
//設置節點自轉角度
void setRotation(float fRotation);
//獲取節點自轉角度
float getRotation();
//zOrder 當有多個節點在Z軸顯示時 引擎會根據它們Z軸的大小決定繪製順序 Z軸大的會覆蓋Z軸小的
//添加子節點 zOrder默認爲0
void addChild(CCNode * child);
//添加子節點
void addChild(CCNode * child, int zOrder);
//添加子節點 指定節點zOrder和節點tag
void addChild(CCNode* child, int zOrder, int tag);
//通過tag名稱獲取節點
CCNode * getChildByTag(int tag);
//獲取所有子節點
CCArray* getChildren();
//獲取子節點數目
unsigned int getChildrenCount(void);
//設置子節點的父節點
void setParent(CCNode* parent);
//獲取子節點的父節點
CCNode* getParent();
//從父節點中刪除當前子節點
void removeFromParent();
//從父節點中刪除當前子節點 如果Cleanup爲true則刪除當前節點的所有動作及回調函數
void removeFromParentAndCleanup(bool cleanup);
//從父節點中刪除當前子節點 如果Cleanup爲true則刪除當前節點的所有動作
void removeChild(CCNode* child);
//從父節點中刪除當前子節點 並指定Cleanup
void removeChild(CCNode* child, bool cleanup);
//通過tag名稱移除節點
void removeChildByTag(int tag);
//通過tag名稱移除節點並指定Cleanup
void removeChildByTag(int tag, bool cleanup);
//移除所有子節點
void removeAllChildren();
//移除所有子節點 並指定Cleanup
void removeAllChildrenWithCleanup(bool cleanup);
//重新設定節點的zOrder
void reorderChild(CCNode * child, int zOrder);
//重新排序所有子節點
void sortAllChildren();
//獲取節點的tag名稱
int getTag();
//設置節點的tag名稱
void setTag(int nTag);
//獲取節點的CCCamera攝像機 cocos2d-x是通過3D方式繪製2D效果
CCCamera* getCamera();
//判斷當前節點是否在運行
bool isRunning();
//節點開始進入舞臺時的回調事件
void onEnter();
//節點進入舞臺時的回調事件
void onEnterTransitionDidFinish();
//節點離開舞臺時的回調事件
void onExit();
//停止所有運行的動作和回調函數
void cleanup(void);
//繪製節點
void draw(void);
//遞歸visit子節點並重繪
void visit(void);
//返回節點對象的矩形框(由座標寬高組成)
CCRect boundingBox(void);
//設置CCActionManager對象被所有動作使用
void setActionManager(CCActionManager* actionManager);
//獲取被所有動作使用的CCActionManger
CCActionManager* getActionManager();
//執行動作
CCAction* runAction(CCAction* action);
//停止動作
stopAction(CCAction* action);
//停止所有動作
void stopAllActions(void);
//通過tag名稱獲取動作
CCAction* getActionByTag(int tag);
//獲取正在運行的動作數量
unsigned int numberOfRunningActions(void);
//定義一個定時器
void schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay);
//定義一個定時器
void schedule(SEL_SCHEDULE selector, float interval);
//取消一個定時器
void unschedule(SEL_SCHEDULE selector);
//取消所有定時器
void unscheduleAllSelectors(void);
//暫停所有定時器和動作
void pauseSchedulerAndActions(void);
//恢復所有定時器和動作
void resumeSchedulerAndActions(void);