码迷,mamicode.com
首页 > 其他好文 > 详细

2假动作,数据缓冲,CCEaseExponential,CCEaseElastic,CCEaseBounce,CCCallFunc,funcNCallBack,funcNDCallBack,funcO

时间:2016-04-03 21:56:55      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:



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"

#include "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");

    CCSprite * woman = CCSprite::create("woman.png");

    man->setPosition(ccp(100, 160));

 

    CCMoveBy *by = CCMoveBy::create(2,ccp(300,0));

    CCMoveBy *by2 = CCMoveBy::create(2,ccp(300,0));

   

    CCEaseExponentialIn * in = CCEaseExponentialIn::create(by2);

    CCEaseExponentialInOut * out = CCEaseExponentialInOut::create(by2);

    CCEaseExponentialInOut * inOut = CCEaseExponentialInOut::create(by2);

 

//CCEaseElasticIn * in = CCEaseElasticIn::create(by2);

    //CCEaseElasticOut * out = CCEaseElasticOut::create(by2);

    //CCEaseElasticInOut * inOut = CCEaseElasticInOut::create(by2);

 

    //CCEaseBounceIn  *in = CCEaseBounceIn::create(by2);

    //CCEaseBounceOut * out = CCEaseBounceOut::create(by2);

    //CCEaseBounceInOut * inOut = CCEaseBounceInOut::create(by2);

 

    //看精灵的执行速度

    //man->runAction(in);

    //man->runAction(out);

    man->runAction(inOut);

 

    addChild(man);

    return true;

}

 

//原生画图,每一帧都会画图

void T13Action::draw()

{

    CCPointArray *array = CCPointArray::create(6);

   

    array->addControlPoint(ccp(100, 160));

    array->addControlPoint(ccp(200, 160));

    array->addControlPoint(ccp(200, 250));

    array->addControlPoint(ccp(300, 250));

    array->addControlPoint(ccp(300, 160));

    array->addControlPoint(ccp(450, 160));

 

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

//传递CCNode * 类型变量,和无类型变量

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

addChild(man);

案例说明:

无參的假动作

void funcCallBack();

T13Action.h

#ifndef _T13Action_H__

#define _T13Action_H__

#include "cocos2d.h"

#include "TBack.h"

USING_NS_CC;

class T13Action :public TBack

{

public:

    static CCScene * scene();

    CREATE_FUNC(T13Action);

    bool init();

 

    void draw();

 

    //无參的假动作

    void funcCallBack();

    //带调用者的假动作

    void funcNCallBack(CCNode * node);

    //带有调用者和数据的假动作

    void funcNDCallBack(CCNode * node, void * data);

    //带有对象的假动作

    void funcOCallBack(CCObject * obj);

};

 

#endif

T13Action.cpp

#include "T13Action.h"

#include "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");

    CCSprite * woman = CCSprite::create("woman.png");

    man->setPosition(ccp(100, 160));

 

    CCMoveBy *by2 = CCMoveBy::create(2, ccp(300, 0));

    //假动作就是当一个动作运行完了之后又运行的一个动作

    CCCallFunc * func = CCCallFunc::create(this,callfunc_selector(T13Action::funcCallBack));

    CCSequence * seq = CCSequence::create(by2, func, NULL);

 

    man->runAction(seq);

    addChild(man);

    return true;

}

 

//原生画图。每一帧都会画图

void T13Action::draw()

{

    CCPointArray *array = CCPointArray::create(6);

   

    array->addControlPoint(ccp(100, 160));

    array->addControlPoint(ccp(200, 160));

    array->addControlPoint(ccp(200, 250));

    array->addControlPoint(ccp(300, 250));

    array->addControlPoint(ccp(300, 160));

    array->addControlPoint(ccp(450, 160));

 

    ccDrawCardinalSpline(array, 1, 100);

}

 

//无參的假动作

void T13Action::funcCallBack() {

    CCLog("action is over");

}

执行结果(执行速度是变速的):

技术分享

输出结果:

技术分享

4 假动作

#ifndef _T13Action_H__

#define _T13Action_H__

#include "cocos2d.h"

#include "TBack.h"

USING_NS_CC;

class T13Action :public TBack

{

public:

    static CCScene * scene();

    CREATE_FUNC(T13Action);

    bool init();

 

    //无參的假动作

    void funcCallBack();

    //带调用者的假动作

    void funcNCallBack(CCNode * node);

    //带有调用者和数据的假动作

    void funcNDCallBack(CCNode * node, void * data);

    //带有对象的假动作

    void funcOCallBack(CCObject * obj);

};

#endif

#include "T13Action.h"

#include "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");

    CCSprite * woman = CCSprite::create("woman.png");

    man->setPosition(ccp(50, 160));

    woman->setPosition(ccp(50,260));

 

 

    //创建一个CCArray,在使用前调用retain(),要注意的是在最后退出之

    //后要在onExit()中将array进行release()

    CCArray * array = CCArray::create();

    array->retain();

    array->addObject(woman);

 

    CCMoveBy *by2 = CCMoveBy::create(2, ccp(300, 0));

    CCCallFuncN * funcN = CCCallFuncN::create(this,

        callfuncN_selector(T13Action::funcNCallBack));

 

    //调用

    CCCallFuncND *funcND = CCCallFuncND::create(this,

        callfuncND_selector(T13Action::funcNDCallBack),

        (void*)"30");

    CCCallFuncO  * funcO = CCCallFuncO::create(this,

        callfuncO_selector(T13Action::funcOCallBack),

        array);

 

    CCSequence * seq = CCSequence::create(by2, funcO, NULL);

 

    man->runAction(seq);

    addChild(man);

    return true;

}

 

//当中CCNode表示的是动作的运行者

void T13Action::funcNCallBack(CCNode *node)

{

    CCSprite *spr = (CCSprite *)node;

    //将精灵从屏幕上

    //spr->removeFromParentAndCleanup(true);

    CCJumpBy * by = CCJumpBy::create(2, ccp(0,0),100,1);

    spr->runAction(by);

}

 

void T13Action::funcNDCallBack(CCNode * node, void * data)

{

    CCSprite *spr = (CCSprite *)node;

    //以下是取出数据的代码

    CCString * str = CCString::createWithFormat("%s", (char*)data);

    //给精灵旋转

    spr->setRotation(str->floatValue());

}

 

void  T13Action::funcOCallBack(CCObject * obj)

{

    CCArray * array = (CCArray*)obj;

    //array中取出第0个元素

    CCSprite * spr = (CCSprite*)array->objectAtIndex(0);

    addChild(spr);

}

 

 

 

 

 

2假动作,数据缓冲,CCEaseExponential,CCEaseElastic,CCEaseBounce,CCCallFunc,funcNCallBack,funcNDCallBack,funcO

标签:

原文地址:http://www.cnblogs.com/bhlsheji/p/5350425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!