class CC_DLL CCDirector : public CCObject, public TypeInfo
{
public:
CCDirector(void);
virtual ~CCDirector(void);
virtual bool init(void);
virtual long getClassTypeInfo() {
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::CCDirector).name());
return id;
}
1、 属性
// 获取当前与虚拟性场景
inline CCScene* getRunningScene(void) { return m_pRunningScene; }
// 查询、设置fps值
inline double getAnimationInterval(void) { return m_dAnimationInterval; }
virtual void setAnimationInterval(double dValue) = 0;
// 查询是否显示fps值
inline bool isDisplayStats(void) { return m_bDisplayStats; }
inline void setDisplayStats(bool bDisplayStats) { m_bDisplayStats = bDisplayStats; }
// 查询一帧多少秒
inline float getSecondsPerFrame() { return m_fSecondsPerFrame; }
// Get the CCEGLView, where everything is rendered获取gl的窗口视图
inline CCEGLView* getOpenGLView(void) { return m_pobOpenGLView; }
void setOpenGLView(CCEGLView *pobOpenGLView);
inline bool isNextDeltaTimeZero(void) { return m_bNextDeltaTimeZero; }
void setNextDeltaTimeZero(bool bNextDeltaTimeZero);
// 查询当前是否暂停了
inline bool isPaused(void) { return m_bPaused; }
// 获取调用到现在的总帧数
inline unsigned int getTotalFrames(void) { return m_uTotalFrames; }
// 获取投影矩阵
inline ccDirectorProjection getProjection(void) { return m_eProjection; }
void setProjection(ccDirectorProjection kProjection);
/** reshape projection matrix when canvas has been change"*/
void reshapeProjection(const CCSize& newWindowSize);
// 设置视口
void setViewport();
// push场景时,不会接收到cleanup消息,replace场景时会接收到cleanup消息
inline bool isSendCleanupToScene(void) { return m_bSendCleanupToScene; }
// This object will be visited after the main scene is visited.
CCNode* getNotificationNode();
void setNotificationNode(CCNode *node);
// CCDirector delegate. It shall implemente the CCDirectorDelegate protocol导演代理,实现了导演协议
CCDirectorDelegate* getDelegate() const;
void setDelegate(CCDirectorDelegate* pDelegate);
// 返回窗口大小
CCSize getWinSize(void);
// 获取尺寸大小,像素级别的
CCSize getWinSizeInPixels(void);
// 返回可视区域的大小,the value is equal to getWinSize if don't invoke CCEGLView::setDesignResolutionSize()
CCSize getVisibleSize();
// 返回可视区域原点
CCPoint getVisibleOrigin();
// 转换ui坐标系下的坐标到OpenGL坐标系下,Useful to convert (multi) touch coordinates to the current layout (portrait or landscape)
CCPoint convertToGL(const CCPoint& obPoint);
// 转换OpenGL坐标系下坐标到ui坐标系下,Useful to convert node points to window points for calls such as glScissor
CCPoint convertToUI(const CCPoint& obPoint);
场景管理部分
// 运行指定的场景,一个导演一个时刻只能运行一个场景
void runWithScene(CCScene *pScene);
// 将新的场景压入栈中
void pushScene(CCScene *pScene);
// 弹出当前运行的场景
void popScene(void);
// 弹出到根场景
void popToRootScene(void);
// 弹出到指定层的场景
void popToSceneStackLevel(int level);
// 切换场景
void replaceScene(CCScene *pScene);
// 终止执行,释放运行场景
void end(void);
// 暂停运行的场景
void pause(void);
// 重新启动暂停的场景
void resume(void);
// 关闭动画
virtual void stopAnimation(void) = 0;
// 开启动画
virtual void startAnimation(void) = 0;
// 绘制场景
void drawScene(void);
内存帮助
// 清除所有的缓存数据,CCTextureCache, CCSpriteFrameCache, CCLabelBMFont cache
void purgeCachedData(void);
// 设置基于CCConfiguration是我默认值
void setDefaultValues(void);
// OpenGL Helper
// 设置OpenGL的默认值
void setGLDefaultValues(void);
// 开启关闭alpha混合
void setAlphaBlending(bool bOn);
// 开启关闭深度测试
void setDepthTest(bool bOn);
virtual void mainLoop(void) = 0;
// 调度属性
CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler);
// 动作管理
CC_PROPERTY(CCActionManager*, m_pActionManager, ActionManager);
// 触摸调度
CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher);
// 输入调度
CC_PROPERTY(CCKeypadDispatcher*, m_pKeypadDispatcher, KeypadDispatcher);
// 加速调度
CC_PROPERTY(CCAccelerometer*, m_pAccelerometer, Accelerometer);
// 延迟时间
CC_PROPERTY_READONLY(float, m_fDeltaTime, DeltaTime);
// 返回共享的导演实例
static CCDirector* sharedDirector(void);
protected:
/* The CCEGLView, where everything is rendered */
CCEGLView *m_pobOpenGLView;
double m_dAnimationInterval;
double m_dOldAnimationInterval;
/* landscape mode ? */
bool m_bLandscape;
bool m_bDisplayStats;
float m_fAccumDt;
float m_fFrameRate;
CCLabelAtlas *m_pFPSLabel;
CCLabelAtlas *m_pSPFLabel;
CCLabelAtlas *m_pDrawsLabel;
/** Whether or not the Director is paused */
bool m_bPaused;
/* How many frames were called since the director started */
unsigned int m_uTotalFrames;
unsigned int m_uFrames;
float m_fSecondsPerFrame;
/* The running scene */
CCScene *m_pRunningScene;
/* will be the next 'runningScene' in the next frame
nextScene is a weak reference. */
CCScene *m_pNextScene;
/* If YES, then "old" scene will receive the cleanup message */
bool m_bSendCleanupToScene;
/* scheduled scenes */
CCArray* m_pobScenesStack;
/* last time the main loop was updated */
struct cc_timeval *m_pLastUpdate;
/* whether or not the next delta time will be zero */
bool m_bNextDeltaTimeZero;
/* projection used */
ccDirectorProjection m_eProjection;
/* window size in points */
CCSize m_obWinSizeInPoints;
/* content scale factor */
float m_fContentScaleFactor;
/* store the fps string */
char *m_pszFPS;
/* This object will be visited after the scene. Useful to hook a notification node */
CCNode *m_pNotificationNode;
/* Projection protocol delegate */
CCDirectorDelegate *m_pProjectionDelegate;
// CCEGLViewProtocol will recreate stats labels to fit visible rect
friend class CCEGLViewProtocol;
};
CCDirector类
最新推荐文章于 2019-07-24 16:15:47 发布