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);