感谢点评与关注。欢迎转载与分享。
勤奋努力。持之以恒! #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(){}
两张扑克牌资源: