Cocos2d-x结构学习(十一)CCMenuItemImage、CCMenuItemSprite、CCAction、ccp、CCPointMake

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

1、CCMenuItemImage:图像菜单项类,继承自CCMenuItemSprite

class CC_DLL CCMenuItemImage : public CCMenuItemSprite
{
public:
    CCMenuItemImage(){}
    virtual ~CCMenuItemImage(){}

    static CCMenuItemImage* create(const char *normalImage,const char *selectedImage);               //下面是四个创建方面的重载函数
    static CCMenuItemImage* create(const char *normalImage,const char *selectedImage,const char *disabledImage);
    static CCMenuItemImage* create(const char *normalImage,CCObject* target,SEL_MenuHandler selector);
    static CCMenuItemImage* create(const char *normalImage,const char *disabledImage,SEL_MenuHandler selector);
    
    bool init();            //两个初始化函数
    bool initWithNormalImage(const char *normalImage,SEL_MenuHandler selector);

    void setNormalSpriteFrame(CCSpriteFrame* frame);     //精灵帧相关函数
    void setSelectedSpriteFrame(CCSpriteFrame* frame);
    void setDisabledSpriteFrame(CCSpriteFrame* frame);

    static CCMenuItemImage* create();
};
2、CCMenuItemSprite:精灵菜单项类,继承自CCMenuItem
class CC_DLL CCMenuItemSprite : public CCMenuItem
{
    CC_PROPERTY(CCNode*,m_pNormalImage,NormalImage);          //建立3个属性,并设置获取和设置属性函数
    CC_PROPERTY(CCNode*,m_pSelectedImage,SelectedImage);
    CC_PROPERTY(CCNode*,m_pDisabledImage,DisabledImage);
public:
    CCMenuItemSprite()
    :m_pNormalImage(NULL),m_pSelectedImage(NULL),m_pDisabledImage(NULL)
    {}

    static CCMenuItemSprite * create(CCNode* normalSprite,CCNode* selectedSprite,CCNode* disabledSprite = NULL); //3个创建函数
    static CCMenuItemSprite * create(CCNode* normalSprite,SEL_MenuHandler selector);
    static CCMenuItemSprite * create(CCNode* normalSprite,CCNode* disabledSprite,SEL_MenuHandler selector);

    bool initWithNormalSprite(CCNode* normalSprite,SEL_MenuHandler selector);//初始化函数
    
    virtual void selected();                  //选中或取消
    virtual void unselected();
    virtual void setEnabled(bool bEnabled);              //设置是否可用
protected:
    virtual void updateImagesVisibility();               //更新图像可见性
};
3、CCAction:动作执行类,继承自CCObject
class CC_DLL CCAction : public CCObject 
{
public:
    CCAction(void);
    virtual ~CCAction(void);
   
    const char* description();            //返回一个描述字符串
    
    virtual CCObject* copyWithZone(CCZone *pZone);  //复制区域

    virtual bool isDone(void);             //返回动作是否完成

    virtual void startWithTarget(CCNode *pTarget);    //开始

    virtual void stop(void);                        //停止

    virtual void step(float dt);                    //根据事件间隔执行

    virtual void update(float time);             //更新
    
    inline CCNode* getTarget(void) { return m_pTarget; }                     //获得和设置目标
    inline void setTarget(CCNode *pTarget) { m_pTarget = pTarget; }
    
    inline CCNode* getOriginalTarget(void) { return m_pOriginalTarget; }        //设置和获得之前的目标
    inline void setOriginalTarget(CCNode *pOriginalTarget) { m_pOriginalTarget = pOriginalTarget; }

    inline int getTag(void) { return m_nTag; }                   //设置和获得标签
    inline void setTag(int nTag) { m_nTag = nTag; }
public:
    static CCAction* create();
protected:
    CCNode    *m_pOriginalTarget;
    CCNode    *m_pTarget;
    int     m_nTag;
};
4、两个宏:ccp和CCPointMake
#define ccp(__X__,__Y__) cocos2d::CCPointMake((float)(__X__),(float)(__Y__))
#define CCPointMake(x,y) CCPoint((float)(x),(float)(y))
原文链接:https://www.f2er.com/cocos2dx/343795.html

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