cocos2dx學習筆記(選擇器)

2021-06-22 19:15:40 字數 2781 閱讀 9030

選擇器類似於c++中類函式指標機制,用來建立函式指標,表示被指向的類方法

schedule_selector(selector)定時器

callfunc_selector(selector)

callfuncn_selector(selector)

callfun***_selector(selector)

callfunco_selector(selector)

menu_selector(selector)選單

event_selector(selector)事件

compare_selector(selector) 

在ccobject中定義了其相關的巨集

typedefvoid (ccobject::*sel_schedule)(float);

typedefvoid (ccobject::*sel_callfunc)();

typedefvoid (ccobject::*sel_callfuncn)(ccnode*);

typedefvoid (ccobject::*sel_callfun***)(ccnode*,void*);

typedefvoid (ccobject::*sel_callfunco)(ccobject*);

typedefvoid (ccobject::*sel_menuhandler)(ccobject*);

typedefvoid (ccobject::*sel_eventhandler)(ccevent*);

typedefint (ccobject::*sel_compare)(ccobject*);

#define schedule_selector(_selector) (sel_schedule)(&_selector)

#define callfunc_selector(_selector) (sel_callfunc)(&_selector)

#define callfuncn_selector(_selector) (sel_callfuncn)(&_selector)

#define callfun***_selector(_selector) (sel_callfun***)(&_selector)

#define callfunco_selector(_selector) (sel_callfunco)(&_selector)

#define menu_selector(_selector) (sel_menuhandler)(&_selector)

#define event_selector(_selector) (sel_eventhandler)(&_selector)

#define compare_selector(_selector) (sel_compare)(&_selector)

在ccnode中

包含各種schedule定時器的操作

在ccmenuitem中

ccmenuitem* ccmenuitem::create(ccobject*rec, sel_menuhandlerselector)

在ccactioninstant中定義了cccallfunc系列函式

cccallfunc系列函式包括

cccallfunc、

cccallfunn、

cccallfun***、cccallfunco,用來中動作中進行方法的呼叫。

cccallfunc呼叫的方法不包含引數。

cccallfunn呼叫的方法包含乙個ccnode*型別的引數,表示執行動作的物件。

cccallfun***呼叫的方法包含兩個引數,不僅有乙個節點引數,還有乙個自定義引數(ccnode*與void*)

cccallfunco呼叫的方法則包含乙個ccobject*型別的引數

cccallfunc *cccallfunc::create(ccobject* pselectortarget,sel_callfunc selector) 

cccallfuncn * cccallfuncn::create(ccobject* pselectortarget,sel_callfuncn selector)

cccallfun*** * cccallfun***::create(ccobject* pselectortarget,sel_callfun*** selector, void* d)

cccallfunco *cccallfunco::create(ccobject* pselectortarget,sel_callfunco selector, ccobject* pobject)

例子:

ccaction *a1=cccallfunc::create(this, callfunc_selector(a::f1));

this->runaction(a1);

ccaction *a2=cccallfuncn::create(this, callfuncn_selector(a::f2));

this->runaction(a2);

int i;

ccaction *a3=cccallfun***::create(this, callfun***_selector(a::f3),(void*)&i);

this->runaction(a3);

ccobject *obj; ccaction *a4=cccallfunco::create(this, callfunco_selector(a::f4),obj);

this->runaction(a4);

cocos2dx原始碼之 選擇器

typedef void ref sel callfunc typedef void ref sel callfuncn node typedef void ref sel callfun node void typedef void ref sel callfunco ref typedef vo...

Cocos2d x學習筆記1

1.建立新的cocos2d x 3.0 專案 在命令列中輸入 cocos new helloworld 專案名稱 p com.ss.pku 包名字 l cpp 專案型別 d d cocos workspace 專案存放路徑 2.資料夾分析 resource 資料夾 存放資源檔案 include和so...

Cocos2d x學習筆記(7)

1 動作基本概念 ccactiong是動作類的基類,動作作用於ccnode,因此,任何乙個動作都需要ccnode物件來執行。ccaction作為乙個基類,其實質是乙個介面 抽象類 由它派生的實現類才是實際使用的動作。ccaction的絕大多數實現類都派生自ccfinitetimeaction,這個類...