您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x节点(CCProtocols.h)API

2013-12-05 16:56 127 查看
本文来自http://blog.csdn.net/runaying ,引用必须注明出处!


cocos2d-x节点(CCProtocols.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

投影协议、标签接口、texture协议、RGBA协议、混合协议;涉及了透明度,透明度/颜色在 children
和parent之间的传递
///cocos2d-x-3.0alpha0/cocos2dx/include
//投影协议、标签接口、texture协议、RGBA协议、混合协议;涉及了透明度,透明度/颜色 在 children 和parent 之间的传递

#ifndef __CCPROTOCOLS_H__
#define __CCPROTOCOLS_H__

#include "ccTypes.h"
#include "textures/CCTexture2D.h"
#include <string>

NS_CC_BEGIN

/**
* RGBA协议影响节点的颜色和不透明度
*/
class CC_DLL RGBAProtocol
{
public:
/**
* 使用 R,G,B bytes 改变 color
*
* @param color Example: Color3B(255,100,0) means R=255, G=100, B=0
* @js NA
* @lua NA
*/
virtual void setColor(const Color3B& color) = 0;

/**
* Returns 当前使用的颜色。
*
* @return The Color3B contains(包含) R,G,B bytes.
* @js NA
* @lua NA
*/
virtual const Color3B& getColor() const = 0;

/**
* Returns 显示的颜色
*
* @return The Color3B contains(包含)R,G,B bytes.
* @js NA
* @lua NA
*/
virtual const Color3B& getDisplayedColor() const = 0;

/**
* Returns 显示的不透明度.
*
* @return  The opacity(不透明度)of sprite, from 0 ~ 255
* @js NA
* @lua NA
*/
virtual GLubyte getDisplayedOpacity() const = 0;
/**
* Returns 不透明度.
*
*  opacity(不透明度)表示这个节点是透明或不透明.
* 0 表示完全透明, 255 完全不透明.
*
* @return  The opacity(不透明度) of sprite, from 0 ~ 255
* @js NA
* @lua NA
*/
virtual GLubyte getOpacity() const = 0;

/**
* Changes the opacity(不透明度).
*
* @param opacity   从 0 到 255,其中 0 表示完全透明, 255 完全不透明.
* @js NA
* @lua NA
*/
virtual void setOpacity(GLubyte opacity) = 0;

// optional

/**
* Changes the OpacityModifyRGB 属性.
* 如果此属性设置为true,则呈现的颜色会受到透明度的影响.
* 通常, r = r * opacity/255, g = g * opacity/255, b = b * opacity/255.
*
* @param value If true, 不透明度将被用作: glColor(R,G,B,opacity);
*              If false, 不透明度将被用作: glColor(opacity, opacity, opacity, opacity);
* @js NA
* @lua NA
*/
virtual void setOpacityModifyRGB(bool value) = 0;

/**
* Returns 是否使用 glColor(R,G,B,opacity)or glColor(opacity, opacity, opacity, opacity) 应用不透明度
*
*
* @return  不透明修改标志.
* @js NA
* @lua NA
*/
virtual bool isOpacityModifyRGB() const = 0;

/**
*  是否把颜色传播到它的 children.
* @js NA
* @lua NA
*/
virtual bool isCascadeColorEnabled() const = 0;
/**
* @js NA
* @lua NA
*/
virtual void setCascadeColorEnabled(bool cascadeColorEnabled) = 0;

/**
*  递归方法更新显示颜色
* @js NA
* @lua NA
*/
virtual void updateDisplayedColor(const Color3B& color) = 0;

/**
*  是否把透明度传播到它的 children.
* @js NA
* @lua NA
*/
virtual bool isCascadeOpacityEnabled() const = 0;
/**
* @js NA
* @lua NA
*/
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) = 0;

/**
*  递归方法更新显示透明度.
* @js NA
* @lua NA
*/
virtual void updateDisplayedOpacity(GLubyte opacity) = 0;
};

/**
* 根据glBlendFunc指定混合功能
* 请参阅glBlendFunc in OpenGL ,在OpenGL ES手册
* http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml 更详细的信息
*/
class CC_DLL BlendProtocol
{
public:
/**
* Sets 混合源功能.
*
* @param blendFunc 源和目标之间的像素运算系数
*                  e.g. {GL_ONE, GL_ONE}, {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}.
* @js NA
* @lua NA
*/
virtual void setBlendFunc(const BlendFunc &blendFunc) = 0;

/**
* Returns 目前正在使用的混合函数.
*
* @return BlendFunc结构,源和目标之间的像素运算系数.
* @js NA
* @lua NA
*/
virtual const BlendFunc &getBlendFunc() const = 0;
};

/**
* 节点对象他使用 Texture2D render(呈现)图片
*  texture可以有 blending(混合)的功能.
* 如果 texture 有 alpha premultiplied(预乘)默认混合功能是 :
*   src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA
* else
*   src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA
* 但是你可以随时改变混合功能.
*/
class CC_DLL TextureProtocol : public BlendProtocol
{
public:
/**
* Returns 当前使用的 texture
*
* @return   texture 是当前正在使用的
* @js NA
* @lua NA
*/
virtual Texture2D* getTexture() const = 0;

/**
* Sets a new texuture. It will be retained(保留).
*
* @param   texture 是一个有效的 Texture2D 对象, 它将应用到这个 sprite 对象上.
* @js NA
* @lua NA
*/
virtual void setTexture(Texture2D *texture) = 0;
};

/**
* 标签通用接口
*/
class CC_DLL LabelProtocol
{
public:
/**
* 使用字符串设置一个新的标签
*
* @param label A null terminated(终止) string
* @js NA
* @lua NA
*/
virtual void setString(const char *label) = 0;

/**
* Returns 这个 label 正在使用的字符串
*
* @js NA
* @lua NA
*/
virtual const char* getString() const = 0;
};

/**
* OpenGL projection(投影) protocol
*/
class CC_DLL DirectorDelegate
{
public:
/**
* 当 projection(投影)更新时,将调用 Director 使用自定义的projection(投影)
* @js NA
* @lua NA
*/
virtual void updateProjection() = 0;
};

NS_CC_END

#endif // __CCPROTOCOLS_H__
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: