1
緩沖動作
man->setscale(0.8f);
woman->setscale(0.8f);
man->setposition(ccp(100, 80));
woman->setposition(ccp(100,240));
ccmoveto * manto = ccmoveto::create(2, ccp(400,80));
ccmoveto * womanto = ccmoveto::create(2, ccp(400, 240));
cceaseexponentialin *in = cceaseexponentialin::create(manto);
cceaseexponentialout *out = cceaseexponentialout::create(manto);
cceaseexponentialinout * inout =
cceaseexponentialinout::create(manto);
man->runaction(inout);
woman->runaction(womanto);
cceaseelasticin *in = cceaseelasticin::create(manto);
cceaseelasticout *out = cceaseelasticout::create(manto);
cceaseelasticinout * inout = cceaseelasticinout::create(manto);
#include
"t13action.h"
"appmacros.h"
ccscene *t13action::scene()
{
ccscene *
scene =
ccscene::create();
t13action *
layer =
t13action::create();
scene->addchild(layer);
return
scene;
}
bool
t13action::init()
tback::init();
ccsprite *
man =
ccsprite::create("man.png");
woman =
ccsprite::create("woman.png");
man->setposition(ccp(100,
160));
ccmoveby *by
= ccmoveby::create(2,ccp(300,0));
*by2
cceaseexponentialin * in =
cceaseexponentialin::create(by2);
* out =
cceaseexponentialinout::create(by2);
cceaseexponentialinout *
inout =
//cceaseelasticout * out = cceaseelasticout::create(by2);
//cceaseelasticinout * inout = cceaseelasticinout::create(by2);
*in = cceasebouncein::create(by2);
//cceasebounceout * out = cceasebounceout::create(by2);
//cceasebounceinout * inout = cceasebounceinout::create(by2);
//看精靈的運作速度
//man->runaction(in);
//man->runaction(out);
addchild(man);
true;
//原生繪圖,每一幀都會繪圖
void
t13action::draw()
ccpointarray *array =
ccpointarray::create(6);
array->addcontrolpoint(ccp(100,
array->addcontrolpoint(ccp(200,
250));
array->addcontrolpoint(ccp(300,
array->addcontrolpoint(ccp(450,
ccdrawcardinalspline(array, 1, 100);
運作結果:
2
并行動作和序列動作
ccsequence
中持續時間為所有動作累計的總合,ccsequence
中不可以
有ccrepeatforever
動作。
ccspwan中持續時間為并行動作持續時間最長的決定。
3
假動作
cccallfunc系列動作包括ccallfunc()、cccallfuncn()、cccallfuncnd,以及cccallfunco四個動作,cccallfunc系列動作的字尾”n”表示node參數,指的是執行動作的對象,”d”表示data參數,指的是使用者自定義的資料,”o”表示對象,指的是一個使用者自定義的ccobject參數。在不同的情況下,我們可以根據不同的需求來選擇不同的cccallfunc動作。
typedef void (ccobject::*sel_callfunc)();
//無參類型
typedef void (ccobject::*sel_callfuncn)(ccnode*);
//傳遞ccnode *
類型變量
typedef void (ccobject::*sel_callfuncnd)(ccnode*, void*);
類型變量,和無類型變量
typedef void (ccobject::*sel_callfunco)(ccobject*);
//傳遞ccobject *類型變量
#define callfunc_selector(_selector) (sel_callfunc)(&_selector)
#define callfuncn_selector(_selector) (sel_callfuncn)(&_selector)
#define callfuncnd_selector(_selector) (sel_callfuncnd)(&_selector)
#define callfunco_selector(_selector) (sel_callfunco)(&_selector)
cccallfunc * func = cccallfunc::create(this,
callfunc_selector(t13action::funccallback));
cccallfuncn * func = cccallfuncn::create(this,
callfuncn_selector(t13action::funcncallback));
cccallfuncnd * func = cccallfuncnd::create(this,
callfuncnd_selector(t13action::funcndcallback), (void *)"30");
ccarray * array = ccarray::create();
array->addobject(woman);
cccallfunco * func = cccallfunco::create(this,
callfunco_selector(t13action::funcocallback),(ccobject*)array);
ccsequence * seq = ccsequence::create(to, func, null);
man->runaction(seq);
案例說明:
無參的假動作
funccallback();
t13action.h
#ifndef
_t13action_h__
#define
"cocos2d.h"
"tback.h"
using_ns_cc;
class
t13action :public
tback
public:
static
scene();
create_func(t13action);
init();
draw();
//無參的假動作
//帶調用者的假動作
funcncallback(ccnode
* node);
//帶有調用者和資料的假動作
funcndcallback(ccnode
* node,
void *
data);
//帶有對象的假動作
funcocallback(ccobject
* obj);
};
#endif
t13action.cpp
ccmoveby *by2
= ccmoveby::create(2,
ccp(300, 0));
//假動作就是當一個動作執行完了之後又執行的一個動作
cccallfunc *
func =
cccallfunc::create(this,callfunc_selector(t13action::funccallback));
ccsequence *
seq =
ccsequence::create(by2,
func,
null);
t13action::funccallback()
cclog("action
is over");
運作結果(運作速度是變速的):
輸出結果:
4
man->setposition(ccp(50,
woman->setposition(ccp(50,260));
//建立一個ccarray,在使用前調用retain(),要注意的是在最後退出之
//後要在onexit()中将array進行release()
ccarray * array =
ccarray::create();
array->retain();
cccallfuncn *
funcn =
cccallfuncn::create(this,
//調用
cccallfuncnd *funcnd
= cccallfuncnd::create(this,
callfuncnd_selector(t13action::funcndcallback),
(void*)"30");
cccallfunco
* funco =
cccallfunco::create(this,
callfunco_selector(t13action::funcocallback),
array);
funco,
//其中ccnode表示的是動作的執行者
t13action::funcncallback(ccnode
*node)
ccsprite *spr
= (ccsprite *)node;
//将精靈從螢幕上
//spr->removefromparentandcleanup(true);
ccjumpby *
by =
ccjumpby::create(2,
ccp(0,0),100,1);
spr->runaction(by);
t13action::funcndcallback(ccnode
data)
//下面是取出資料的代碼
ccstring *
str =
ccstring::createwithformat("%s",
(char*)data);
//給精靈旋轉
spr->setrotation(str->floatvalue());
void
t13action::funcocallback(ccobject
* obj)
ccarray * array = (ccarray*)obj;
//從array中取出第0個元素
spr = (ccsprite*)array->objectatindex(0);
addchild(spr);