Cocos2d-x结构学习(七)CCDirector、CCLabelTTF、CCLabelProtocol、CC_PROPERTY、TypeInfo

Cocos2d-x结构学习(七)CCDirector、CCLabelTTF、CCLabelProtocol、CC_PROPERTY、TypeInfo,第1张

概述1、CCLabelTTF:字体处理类,继承自CCSprite和CCLabelProtocol class CC_DLL CCLabelTTF : public CCSprite, public CCLabelProtocol{public: CCLabelTTF(); virtual ~CCLabelTTF(); const char* description()

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);                           //从堆栈d出一个场景    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;};
总结

以上是内存溢出为你收集整理的Cocos2d-x结构学习(七)CCDirector、CCLabelTTF、CCLabelProtocol、CC_PROPERTY、TypeInfo全部内容,希望文章能够帮你解决Cocos2d-x结构学习(七)CCDirector、CCLabelTTF、CCLabelProtocol、CC_PROPERTY、TypeInfo所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1051416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存