COCOS2D X 精靈建立隨筆

2021-09-06 18:33:06 字數 1583 閱讀 7905

ccsprite類中建立sprite的方法都是靜態的:

static ccsprite* create ( )建立乙個無顯示的精靈,可隨後用 settexture 方法設定顯示

static ccsprite* create ( const char * pszfilename )依據路徑建立精靈,該精靈為整張

static ccsprite* create ( const char * pszfilename,const ccrect & rect )依據指定選取的區域建立精靈,該精靈顯示為該指定的區域

依據路徑建立精靈的方法一般使用於載入頻率低的精靈建立,這樣的型別的方法在建立精靈時,每次都會對進行對應的處理,會損耗一定的執行時間。

static ccsprite* createwithspriteframe ( ccspriteframe * pspriteframe )依據精靈幀建立精靈

ccspriteframe(精靈幀)中主要包含cctexture2d紋理、矩形大小,用來表示乙個精靈。主要獲取方法:

static ccspriteframe * create (const char *filename, const ccrect &rect)

static ccspriteframe* create ( const char * filename,const ccrect & rect,bool rotated,const ccpoint & offset,const ccsize & originalsize )

通過指定檔案獲取

static ccspriteframe* createwithtexture ( cctexture2d * pobtexture,const ccrect & rect )

static ccspriteframe* createwithtexture ( cctexture2d * pobtexture,const ccrect & rect,bool rotated,const ccpoint & offset,const ccsize & originalsize )

通過紋理圖獲取 

static ccsprite* createwithspriteframename ( const char * pszspriteframename )依據精靈幀名建立精靈

通過精靈幀建立精靈,能夠通過非常多方法獲取,精靈幀僅僅是用於儲存精靈顯示乙個類,該類能對終於顯示的精靈進行各種改動

static ccsprite* createwithtexture ( cctexture2d * ptexture )依據紋理建立精靈

static ccsprite* createwithtexture ( cctexture2d * ptexture,const ccrect & rect )依據指定紋理區域建立精靈

cctexture2d 為載入在記憶體中的紋理圖

cocos2d x建立精靈

建立精靈 方法一 有一張檔案建立 l ocal spritename cc.sprite create test.dog cc.sprite會自動將檔案載入為紋理,並用於初始化精靈 精靈還可以僅顯示的一部分 l ocal spritename cc.sprite create test.png cc...

cocos2d x中快取幀精靈建立

初玩cocos2d x在用快取幀方式建立精靈時,出了問題,折騰了一早上,去掉所有的類,直接在一類中編寫,ccspriteframecache sharedspriteframecache addspriteframeswithfile spfont.plist ccspritebatchnode b...

cocos2d x中的精靈

所有的遊戲都有 sprites 精靈,你可能知道或者不知道它們是什麼。精靈就是遊戲中在場景裡進行移動的物件。你可以操縱它們。精靈可能是遊戲中最主要的角色。我知道你在想什麼 難道每乙個圖形物件都是精靈sprite嗎?當然不是!為什麼?當你操縱乙個精靈的時候,它就是乙個精靈。如果你不對它進行操作,那它就...