博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2dx 利用CCOrbitCamera实现扑克牌翻牌效果
阅读量:5225 次
发布时间:2019-06-14

本文共 3336 字,大约阅读时间需要 11 分钟。

感谢点评与关注。欢迎转载与分享。

勤奋努力。持之以恒!
#include "HelloWorldScene.h"#include "SimpleAudioEngine.h"using namespace cocos2d;using namespace CocosDenshion;CCScene* HelloWorld::scene(){    CCScene *scene = CCScene::create();    HelloWorld *layer = HelloWorld::create();    scene->addChild(layer);    return scene;}bool HelloWorld::init(){    if ( !CCLayer::init() )    {        return false;    }    size = CCDirector::sharedDirector()->getWinSize();        //加一背景    CCLayerColor* background = CCLayerColor::create(ccc4(255, 180, 255, 255), size.width, size.height);    this->addChild(background);        actionIsDone = true;//标示动作是否完毕        createPoker(); //创建扑克        return true;}//创建扑克void HelloWorld::createPoker(){    //扑克牌正面    CCSprite* pokerFront = CCSprite::create("poker_front.png");    pokerFront->setVisible(false);    pokerFront->setPosition(ccp(size.width/2, size.height/2));    this->addChild(pokerFront,1,123);      //扑克牌反面    CCSprite* pokerBack = CCSprite::create("poker_back.png");    pokerBack->setPosition(pokerFront->getPosition());    this->addChild(pokerBack,1,321);}//翻牌动作void HelloWorld::startOrbitAction(){    //扑克牌正面    CCSprite* pokerFront = (CCSprite*)this->getChildByTag(123);    //扑克牌反面    CCSprite* pokerBack = (CCSprite*)this->getChildByTag(321);        float orbitTime = 1;    if (pokerFront->isVisible() == false && actionIsDone == true) {        actionIsDone = false;        //第一个參数是旋转的时间,第二个參数是起始半径,第三个參数半径差,第四个參数是起始Z角,第五个參数是旋转Z角差,第六个參数是起始X角。最后一个參数旋转X角差,        CCOrbitCamera* orbitFront = CCOrbitCamera::create(orbitTime, 1, 0, 270, 90, 0, 0);        CCSequence* sequenceFront = CCSequence::createWithTwoActions(CCShow::create(), orbitFront);        CCTargetedAction* targetFront = CCTargetedAction::create(pokerFront, sequenceFront);        CCOrbitCamera* orbitBack = CCOrbitCamera::create(orbitTime, 1, 0, 0, 90, 0, 0);        pokerBack->runAction(CCSequence::create(orbitBack, CCHide::create(), targetFront, CCCallFunc::create(this, callfunc_selector(HelloWorld::actionIsDownFunc)),NULL));    }else if(pokerFront->isVisible() == true && actionIsDone == true){        actionIsDone = false;        CCOrbitCamera* orbitFront = CCOrbitCamera::create(orbitTime, 1, 0, 270, 90, 0, 0);        CCSequence* sequenceFront = CCSequence::createWithTwoActions(CCShow::create(), orbitFront);        CCTargetedAction* targetFront = CCTargetedAction::create(pokerBack, sequenceFront);                CCOrbitCamera* orbitBack = CCOrbitCamera::create(orbitTime, 1, 0, 0, 90, 0, 0);        pokerFront->runAction(CCSequence::create(orbitBack, CCHide::create(), targetFront, CCCallFunc::create(this, callfunc_selector(HelloWorld::actionIsDownFunc)),NULL));    }}void HelloWorld::actionIsDownFunc(){    actionIsDone = true;}bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){    //翻牌动作    startOrbitAction();    return true;}void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){}void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){}void HelloWorld::onEnter(){    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);    CCLayer::onEnter();}void HelloWorld::onExit(){    CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);    CCLayer::onExit();}HelloWorld::~HelloWorld(){}

两张扑克牌资源:

                         

转载于:https://www.cnblogs.com/mengfanrong/p/5121547.html

你可能感兴趣的文章
为什么分布式一定要有Redis?
查看>>
hihoCoder 1233 : Boxes(盒子)
查看>>
HihoCoder 1328 BFS 搜索
查看>>
Day2-h和p标签
查看>>
[回归分析][7]--定性预测变量
查看>>
团队的绩效评估计划
查看>>
纯css实现警示框页面(带关闭窗口按钮)
查看>>
django的views里面的request对象详解大全
查看>>
oracle中anyData数据类型的使用实例
查看>>
C++对vector里面的元素排序及取任意重叠区间
查看>>
蓝桥杯题——包子凑数
查看>>
软件测试——性能测试总结
查看>>
PycharmV2017 1.x使用说明手册
查看>>
Spring基于注解的配置概述
查看>>
【hive】函数大全
查看>>
Linux/Windows远程桌面
查看>>
我对IoC/DI的理解
查看>>
Struts2数据传输的背后机制:ValueStack(值栈)
查看>>
SVN的基本操作
查看>>
信用卡、借记卡
查看>>