今天在學習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就可以使用自動管理內存了。然後我們來看下它的一些函數: