今天在学习CCAction源码时,看到CCActionCatmullRom文件时,发现其中有个辅助类CCPointArray,记下来,方便以后也用到这种类型,其实我们大可自己实现,但是既然有了,就可以进行自己随意用了。先看下源码声明:
class CC_DLL CCPointArray : public CCObject
{
public:
/** creates and initializes a Points array with capacity
* @lua NA
*/
static CCPointArray* create(unsigned int capacity); 根据参数capacity的大小来创建CCPointArray对象
/**
* @lua NA
*/
virtual ~CCPointArray(); 析构函数
/**
* @lua NA
*/
CCPointArray(); 构造函数
/** initializes a Catmull Rom config with a capacity hint */
bool initWithCapacity(unsigned int capacity); 在调用create函数时会调用此函数
/** appends a control point */
void addControlPoint(CCPoint controlPoint); 添加一个CCPoint到CCPointArray对象
/** inserts a controlPoint at index */
void insertControlPoint(CCPoint &controlPoint, unsigned int index); 插入一个CCPoint到CCPointArray的index位置
/** replaces an existing controlPoint at index */
void replaceControlPoint(CCPoint &controlPoint, unsigned int index); 替换CCPointArray的index位置的数据为CCPoint
/** get the value of a controlPoint at a given index */
CCPoint getControlPointAtIndex(unsigned int index); 返回CCPointArray的index位置的数据CCPoint
/** deletes a control point at a given index */
void removeControlPointAtIndex(unsigned int index); 移除CCPointArray的index位置的CCPoint
/** returns the number of objects of the control point array */
unsigned int count(); CCPointArray中CCPoint的个数
/** returns a new copy of the array reversed. User is responsible for releasing this copy */
CCPointArray* reverse();
/** reverse the current control point array inline, without generating a new one */
void reverseInline();
/**
* @js NA
* @lua NA
*/
virtual CCObject* copyWithZone(CCZone *zone);
const std::vector<CCPoint*>* getControlPoints();
void setControlPoints(std::vector<CCPoint*> *controlPoints);
private:
/** Array that contains the control points */
std::vector<CCPoint*> *m_pControlPoints;
};
继承自CCObject,继承CCObject是为了用到内存管理方面的知识,因为CCObject实现了采用了引用计数的方式,这样子类只要继承CCObject就可以使用自动管理内存了。然后我们来看下它的一些函数:
class CC_DLL CCPointArray : public CCObject
{
public:
/** creates and initializes a Points array with capacity
* @lua NA
*/
static CCPointArray* create(unsigned int capacity); 根据参数capacity的大小来创建CCPointArray对象
/**
* @lua NA
*/
virtual ~CCPointArray(); 析构函数
/**
* @lua NA
*/
CCPointArray(); 构造函数
/** initializes a Catmull Rom config with a capacity hint */
bool initWithCapacity(unsigned int capacity); 在调用create函数时会调用此函数
/** appends a control point */
void addControlPoint(CCPoint controlPoint); 添加一个CCPoint到CCPointArray对象
/** inserts a controlPoint at index */
void insertControlPoint(CCPoint &controlPoint, unsigned int index); 插入一个CCPoint到CCPointArray的index位置
/** replaces an existing controlPoint at index */
void replaceControlPoint(CCPoint &controlPoint, unsigned int index); 替换CCPointArray的index位置的数据为CCPoint
/** get the value of a controlPoint at a given index */
CCPoint getControlPointAtIndex(unsigned int index); 返回CCPointArray的index位置的数据CCPoint
/** deletes a control point at a given index */
void removeControlPointAtIndex(unsigned int index); 移除CCPointArray的index位置的CCPoint
/** returns the number of objects of the control point array */
unsigned int count(); CCPointArray中CCPoint的个数
/** returns a new copy of the array reversed. User is responsible for releasing this copy */
CCPointArray* reverse();
/** reverse the current control point array inline, without generating a new one */
void reverseInline();
/**
* @js NA
* @lua NA
*/
virtual CCObject* copyWithZone(CCZone *zone);
const std::vector<CCPoint*>* getControlPoints();
void setControlPoints(std::vector<CCPoint*> *controlPoints);
private:
/** Array that contains the control points */
std::vector<CCPoint*> *m_pControlPoints;
};
继承自CCObject,继承CCObject是为了用到内存管理方面的知识,因为CCObject实现了采用了引用计数的方式,这样子类只要继承CCObject就可以使用自动管理内存了。然后我们来看下它的一些函数: