COCOS2D X FRAME動畫創作隨筆

2021-09-07 02:19:09 字數 2577 閱讀 7770

ccanimate繼承ccactioninterval,和ccanimate是一家action,有著action所有的屬性和方法。

ccanimate一些重要的方法:

static ccanimate* create ( ccanimation * panimation )依據animation建立animate

virtual ccanimation* getanimation ( void )依據animate獲得animation

bool initwithanimation ( ccanimation * panimation )依據animation初始化僅僅建立了animate物件的例項

virtual ccactioninterval* reverse ( void )獲得animate物件反序物件

virtual void setanimation ( ccanimation * var )設定animation

virtual void stop ( void )停止動作

由全部建立ccanimate方法發現,全部的物件都是依據animation來建立。

static ccanimation * createwithspriteframes (ccarray *arrayofspriteframenames, float delay=0.0f)通過ccarray 和延時來建立ccanimation 

ccarray 是乙個ccspriteframe陣列。表示該ccanimation全部的動畫幀。delay表示動畫的延遲時間。每乙個動畫幀間的時間間隔。

static ccarray* createwithcapacity ( unsigned int capacity )依據動畫幀數建立陣列容量。用於存放各個動畫幀。

ccarray 中的ccspriteframe表示精靈動作的某幀,ccspriteframe的建立方法與使用精靈幀建立精靈一樣。

動畫建立中會使用到各種,若每次在載入時都進行處理。則會浪費非常多系統資源,cocos2d-x中通過cctexturecache來解決問題。

cctexturecache為紋理快取類,該類是乙個單例項類:

static cctexturecache* sharedtexturecache ( )獲得cctexturecache單例項物件。

static void purgesharedtexturecache ( )清理全部的快取

void removetexture ( cctexture2d * texture )依據cctexture2d 物件刪除快取

void removetextureforkey ( const char * texturekeyname )依據cctexture2d 物件名刪除快取

void removeunusedtextures ( )清除掉全部沒有再使用的快取

cctexture2d* addimage ( const char * fileimage )通過路徑,將該紋理加入快取。若該路徑已經加入過則直接獲取紋理物件。

當某一動畫須要頻繁使用時。相同使用動畫快取類來解決動畫反覆呼叫問題:

ccanimationcache 用於管理動畫快取。該類為單例項。

static ccanimationcache * sharedanimationcache (void)獲取ccanimationcache 單例項。

static void purgesharedanimationcache (void)清理ccanimationcache 類快取空間

void addanimation (ccanimation *animation, const char *name)向ccanimationcache 中加入animation物件,並以唯一表示字串標識

void removeanimationbyname (const char *name)通過唯一標識字串刪除animation物件

ccanimation * animationbyname (const char *name)通過唯一標識字串獲取已經加入的animation物件

其它方法省略

全部快取類的使用儘管提供了跟快的處理速度,可是犧牲了系統記憶體為代價,使用時應當擇優使用

frame動畫總結:動畫是由詳細精靈來展現。首先得到精靈的動作的全部動作幀 ccspriteframe,再通過ccarray 物件將全部的在同一動作中的動畫幀組合起來。

通過這一系列的已經組合的動畫幀建立出animation物件,完畢真正的動畫。

執行動畫動作需要完成,因此,建立ccanimate行動,使執行該嚮導。

Cocos新增動畫

studio 匯出使用大圖 和 使用全部大圖 匯出使用大圖 生成 png plist和畫布對應的json 裡載入畫布使用了同樣的方式 將大圖切開存入緩衝池 cc.spriteframecache.addspriteframes res.calcplist 逐幀動畫 將多張存入陣列 然後使用 var ...

cocos2d動畫用例

animation.h import box2d.h import cocos2d.h import bysingle.h inte ce animspritefactory nsobject id init ccsprite genanimsprite cgpoint position animn...

Cocos2d x 2 1 5 簡單動畫

cocos2d新版本函式更改了一些。下面的 可以產生乙個簡單動畫。第一步 生成動畫需要的資料 cctexture2d texture cctexturecache sharedtexturecache addimage image.png ccspriteframe frmae0 ccspritef...