1、CCLabelTTF:字体处理类,继承自CCSprite和CCLabelProtocol
class CC_DLL CCLabelTTF : public CCSprite,public CCLabelProtocol { public: CCLabelTTF(); virtual ~CCLabelTTF(); const char* description(); //获取描述信息 static CCLabelTTF * create(const char *string,const char *fontName,float fontSize); //几个创建相关的函数 static CCLabelTTF * create(const char *string,float fontSize,const CCSize& dimensions,CCTextAlignment hAlignment); static CCLabelTTF * create(const char *string,CCTextAlignment hAlignment,CCVerticalTextAlignment vAlignment); static CCLabelTTF * createWithFontDefinition(const char *string,ccFontDefinition &textDefinition); bool initWithString(const char *string,float fontSize); //几个初始化相关的函数 bool initWithString(const char *string,CCTextAlignment hAlignment); bool initWithString(const char *string,CCVerticalTextAlignment vAlignment); bool initWithStringAndTextDefinition(const char *string,ccFontDefinition &textDefinition); void setTextDefinition(ccFontDefinition *theDefinition); //设置和获得纹理定义 ccFontDefinition * getTextDefinition(); void enableShadow(const CCSize &shadowOffset,float shadowOpacity,float shadowBlur,bool mustUpdateTexture = true); //两个阴影相关函数 void disableShadow(bool mustUpdateTexture = true); void enableStroke(const ccColor3B &strokeColor,float strokeSize,bool mustUpdateTexture = true); void disableStroke(bool mustUpdateTexture = true); void setFontFillColor(const ccColor3B &tintColor,bool mustUpdateTexture = true); //设置字体的填出颜色 bool init(); static CCLabelTTF * create(); virtual void setString(const char *label); //设置和获得字符串 virtual const char* getString(void); CCTextAlignment getHorizontalAlignment(); //设置和获得水平对齐 void setHorizontalAlignment(CCTextAlignment alignment); CCVerticalTextAlignment getVerticalAlignment(); //设置和获得垂直对齐 void setVerticalAlignment(CCVerticalTextAlignment verticalAlignment); CCSize getDimensions(); //设置和获得尺寸 void setDimensions(const CCSize &dim); float getFontSize(); //设置和获得字体尺寸 void setFontSize(float fontSize); const char* getFontName(); //获得和设置字体名字 void setFontName(const char *fontName); private: bool updateTexture(); %2�q@ //更新纹理 protected: void _updateWithTextDefinition(ccFontDefinition & textDefinition,bool mustUpdateTexture = true); ccFontDefinition _prepareTextDefinition(bool adjustForResolution = false); CCSize m_tDimensions; CCTextAlignment m_hAlignment; CCVerticalTextAlignment m_vAlignment; std::string * m_pFontName; float m_fFontSize; std::string m_string; bool m_shadowEnabled; CCSize m_shadowOffset; float m_shadowOpacity; float m_shadowBlur; bool m_strokeEnabled; ccColor3B m_strokeColor; float m_strokeSize; ccColor3B m_textFillColor; };2、CCLabelProtocol:标签协议类,两个函数,设置字符串和获得字符串
class CC_DLL CCLabelProtocol { public: virtual void setString(const char *label) = 0; virtual const char* getString(void) = 0; };3、CCDirector:导演类,可以处理场景间的切换等,继承自CCObject和TypeInfo
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; } //获得类信息 inline CCScene* getRunningScene(void) { return m_pRunningScene; } //获得正在运行的场景 inline double getAnimationInterval(void) { return m_dAnimationInterval; } //获得和设置动画帧率 virtual void setAnimationInterval(double dValue) = 0; inline bool isDisplayStats(void) { return m_bDisplayStats; } //判断或获得是否在屏幕上显示帧率信息 inline void setDisplayStats(bool bDisplayStats) { m_bDisplayStats = bDisplayStats; } inline float getSecondsPerFrame() { return m_fSecondsPerFrame; }
inline CCEGLView* getOpenGLView(void) { return m_pobOpenGLView; } //设置和获得openGL视口 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; } //openGl投影相关 void setProjection(ccDirectorProjection kProjection); void reshapeProjection(const CCSize& newWindowSize); void setViewport(); //设置openGL视口 inline bool isSendCleanupToScene(void) { return m_bSendCleanupToScene; } CCNode* getNotificationNode(); void setNotificationNode(CCNode *node); CCDirectorDelegate* getDelegate() const; //获得和设置委派 void setDelegate(CCDirectorDelegate* pDelegate); CCSize getWinSize(void); //以下几个均和openGL相关,坐标转换,窗体大小,可见大小等 CCSize getWinSizeInPixels(void); CCSize getVisibleSize(); CCPoint getVisibleOrigin(); CCPoint convertToGL(const CCPoint& obPoint); CCPoint convertToUI(const CCPoint& obPoint); float getZEye(void); void runWithScene(CCScene *pScene); //运行场景 void pushScene(CCScene *pScene); //压入一个场景进堆栈 void popScene(void); //从堆栈弹出一个场景 void popToRootScene(void); 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); //绘制场景 void purgeCachedData(void); void setDefaultValues(void); void setGLDefaultValues(void); void setAlphaBlending(bool bOn); //启用和禁用混合及深度测试 void setDepthTest(bool bOn); virtual void mainLoop(void) = 0; //主循环
void setContentScaleFactor(float scaleFactor); //设置上下文缩放因子 float getContentScaleFactor(void); public: 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); public: static CCDirector* sharedDirector(void); //获取实例指针 protected: void purgeDirector(); bool m_bPurgeDirecotorInNextLoop; void setNextScene(void); void showStats(); void createStatsLabel(); void calculateMPF(); void getFPSImageData(unsigned char** datapointer,unsigned int* length); void calculateDeltaTime(); protected: CCEGLView *m_pobOpenGLView; double m_dAnimationInterval; double m_dOldAnimationInterval; bool m_bLandscape; bool m_bDisplayStats; float m_fAccumDt; float m_fFrameRate; CCLabelAtlas *m_pFPSLabel; CCLabelAtlas *m_pSPFLabel; CCLabelAtlas *m_pDrawsLabel; bool m_bPaused; unsigned int m_uTotalFrames; unsigned int m_uFrames; float m_fSecondsPerFrame; CCScene *m_pRunningScene; CCScene *m_pNextScene; bool m_bSendCleanupToScene; CCArray* m_pobScenesStack; struct cc_timeval *m_pLastUpdate; bool m_bNextDeltaTimeZero; ccDirectorProjection m_eProjection; CCSize m_obWinSizeInPoints; float m_fContentScaleFactor; char *m_pszFPS; CCNode *m_pNotificationNode; CCDirectorDelegate *m_pProjectionDelegate; friend class CCEGLViewProtocol; };4、CC_PROPERTY:一个带定义,设置和获得属性的宏,简化工作
#define CC_PROPERTY(varType,varName,funName)\ protected: varType varName;\ public: virtual varType get##funName(void);\ public: virtual void set##funName(varType var);5、TypeInfo:一个简单的小型类,可以获得类的信息
class TypeInfo { public: virtual long getClassTypeInfo() = 0; };