class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
{
public:
CCLayer();
virtual ~CCLayer();
virtual bool init();
// 创建layer层
static CCLayer *create(void);
// 重写父类方法
virtual void onEnter();
virtual void onExit();
virtual void onEnterTransitionDidFinish();
// 单点触屏的默认实现,开始,移动,结束,取消
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
// 多点触屏的默认实现
virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent);
// 实现加速
virtual void didAccelerate(CCAcceleration* pAccelerationValue);
// 注册、销毁脚本加速控制器
void registerScriptAccelerateHandler(int nHandler);
void unregisterScriptAccelerateHandler(void);
// 注册触屏调度事件,在OnEnter中调用
virtual void registerWithTouchDispatcher(void);
// 注册脚本调度事件处理器
virtual void registerScriptTouchHandler(int nHandler, bool bIsMultiTouches = false, int nPriority = INT_MIN, bool bSwallowsTouches = false);
// 取消注册脚本调度处理
virtual void unregisterScriptTouchHandler(void);
// 是否开启响应触屏事件
virtual bool isTouchEnabled();
virtual void setTouchEnabled(bool value);
// 设置触屏模式
virtual void setTouchMode(ccTouchesMode mode);
virtual int getTouchMode();
// 设置触屏事件的优先级,默认为0
virtual void setTouchPriority(int priority);
virtual int getTouchPriority();
// 是否开启加速事件
virtual bool isAccelerometerEnabled();
virtual void setAccelerometerEnabled(bool value);
// 设置加速事件的间隔
virtual void setAccelerometerInterval(double interval);
// 查询是否允许输入文字事件
virtual bool isKeypadEnabled();
virtual void setKeypadEnabled(bool value);
// 注册、销毁脚本输入文字事件控制器
void registerScriptKeypadHandler(int nHandler);
void unregisterScriptKeypadHandler(void);
// 返回键按下时调用,menu按下时调用
virtual void keyBackClicked(void);
virtual void keyMenuClicked(void);
// 获取脚本触屏控制入口,键盘输入控制入口,加速入口
inline CCTouchScriptHandlerEntry* getScriptTouchHandlerEntry() { return m_pScriptTouchHandlerEntry; };
inline CCScriptHandlerEntry* getScriptKeypadHandlerEntry() { return m_pScriptKeypadHandlerEntry; };
inline CCScriptHandlerEntry* getScriptAccelerateHandlerEntry() { return m_pScriptAccelerateHandlerEntry; };
protected:
bool m_bTouchEnabled;
bool m_bAccelerometerEnabled;
bool m_bKeypadEnabled;
private:
// Script touch events handler
CCTouchScriptHandlerEntry* m_pScriptTouchHandlerEntry;
CCScriptHandlerEntry* m_pScriptKeypadHandlerEntry;
CCScriptHandlerEntry* m_pScriptAccelerateHandlerEntry;
int m_nTouchPriority;
ccTouchesMode m_eTouchMode;
int excuteScriptTouchHandler(int nEventType, CCTouch *pTouch);
int excuteScriptTouchHandler(int nEventType, CCSet *pTouches);
};
// 增加了颜色和透明度属性
class CC_DLL CCLayerRGBA : public CCLayer, public CCRGBAProtocol
{
public:
CREATE_FUNC(CCLayerRGBA);
CCLayerRGBA();
virtual ~CCLayerRGBA();
virtual bool init();
virtual GLubyte getOpacity();
virtual GLubyte getDisplayedOpacity();
virtual void setOpacity(GLubyte opacity);
virtual void updateDisplayedOpacity(GLubyte parentOpacity);
virtual bool isCascadeOpacityEnabled();
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
virtual const ccColor3B& getColor();
virtual const ccColor3B& getDisplayedColor();
virtual void setColor(const ccColor3B& color);
virtual void updateDisplayedColor(const ccColor3B& parentColor);
virtual bool isCascadeColorEnabled();
virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
virtual void setOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
virtual bool isOpacityModifyRGB() { return false; }
};
// 增加混合属性
class CC_DLL CCLayerColor : public CCLayerRGBA, public CCBlendProtocol
{
protected:
ccVertex2F m_pSquareVertices[4];
ccColor4F m_pSquareColors[4];
public:
CCLayerColor();
virtual ~CCLayerColor();
virtual void draw();
// 设置内容大小
virtual void setContentSize(const CCSize & var);
// 创建颜色的layer层,颜色-宽度-高度,默认的宽高分别为窗口宽高
static CCLayerColor* create();
static CCLayerColor * create(const ccColor4B& color, GLfloat width, GLfloat height);
static CCLayerColor * create(const ccColor4B& color);
// 初始化层的属性,颜色-宽度-高度
virtual bool init();
virtual bool initWithColor(const ccColor4B& color, GLfloat width, GLfloat height);
virtual bool initWithColor(const ccColor4B& color);
// 改变颜色层的宽度、高度
void changeWidth(GLfloat w);
void changeHeight(GLfloat h);
void changeWidthAndHeight(GLfloat w ,GLfloat h);
// 定义混合属性
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
// 设置颜色、透明度
virtual void setColor(const ccColor3B &color);
virtual void setOpacity(GLubyte opacity);
};
// 属性宏定义
#define CC_PROPERTY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void);\
public: virtual void set##funName(varType var);
class CC_DLL CCLayerGradient : public CCLayerColor
{
public:
// 创建一个阶梯层,颜色变化从start到end,
static CCLayerGradient* create();
static CCLayerGradient* create(const ccColor4B& start, const ccColor4B& end);
// 在创建层时指定变化方向
static CCLayerGradient* create(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);
// 初始化该层,方向,起始颜色,终点颜色
virtual bool init();
virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end);
virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);
// 增加起始颜色,终点颜色,起始透明度,终止透明度,和变化方向
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_startColor, StartColor)
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_endColor, EndColor)
CC_PROPERTY(GLubyte, m_cStartOpacity, StartOpacity)
CC_PROPERTY(GLubyte, m_cEndOpacity, EndOpacity)
CC_PROPERTY_PASS_BY_REF(CCPoint, m_AlongVector, Vector)
// 设定压缩差值
virtual void setCompressedInterpolation(bool bCompressedInterpolation);
virtual bool isCompressedInterpolation();
};
// 支持多个孩子,但只有一个活动层
class CC_DLL CCLayerMultiplex : public CCLayer
{
protected:
unsigned int m_nEnabledLayer;
CCArray* m_pLayers;
public:
CCLayerMultiplex();
virtual ~CCLayerMultiplex();
static CCLayerMultiplex* create();
// 根据一系列层创建一个CCLayerMultiplex层
static CCLayerMultiplex* createWithArray(CCArray* arrayOfLayers);
// 使用可变数目的层来创建
static CCLayerMultiplex * create(CCLayer* layer, ... );
// 用于lua创建
static CCLayerMultiplex * createWithLayer(CCLayer* layer);
// 添加层
void addLayer(CCLayer* layer);
// 使用可变列表初始化层,
bool initWithLayers(CCLayer* layer, va_list params);
bool initWithArray(CCArray* arrayOfLayers);
// 切换到索引n指定的层
void switchTo(unsigned int n);
// 销毁当前层,并转换到n指定另外一个层
void switchToAndReleaseMe(unsigned int n);
};
CCLayer类
最新推荐文章于 2021-02-01 00:42:59 发布