转自:http://blog.csdn.net/yanghuiliu/article/details/9115833
这个能实现翻牌的action就是CCOrbitCamera。
static CCOrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
参数分别为旋转的时间,起始半径,半径差,起始z角,旋转z角差,起始x角,旋转x角差
下面是我封装的cardSprite
//创建翻牌sprite, 参数:卡片里面的图,卡片的封面,翻牌所花时间
CardSprite* card = CardSprite::create("1.png", "2.png", ); card->setPosition(ccp(size.width * ., size.height * .)); addChild(card);
card->openCard();//开始翻牌
CardSprite.h
//
// CardSprite.h
// Cocos2dev.com
//
// Created by LiuYanghui on 13-6-17.
//
// #ifndef __Test__CardSprite__
#define __Test__CardSprite__ #include "cocos2d.h"
USING_NS_CC; class CardSprite : public CCSprite
{
public:
CardSprite();
~CardSprite();
static CardSprite* create(const char* inCardImageName, const char* outCardImageName, float duration);
virtual bool init(const char* inCardImageName, const char* outCardImageName, float duration); private:
bool m_isOpened;
CCActionInterval* m_openAnimIn;
CCActionInterval* m_openAnimOut; void initData(const char* inCardImageName, const char* outCardImageName, float duration); public:
void openCard();
}; #endif /* defined(__Test__CardSprite__) */
CardSprite.cpp
//
// CardSprite.cpp
// Cocos2dev.com
//
// Created by LiuYanghui on 13-6-17.
//
// #include "CardSprite.h" #define kInAngleZ 270 //里面卡牌的起始Z轴角度
#define kInDeltaZ 90 //里面卡牌旋转的Z轴角度差 #define kOutAngleZ 0 //封面卡牌的起始Z轴角度
#define kOutDeltaZ 90 //封面卡牌旋转的Z轴角度差 enum {
tag_inCard = ,
tag_outCard
}; CardSprite::CardSprite()
{ } CardSprite::~CardSprite()
{
m_openAnimIn->release();
m_openAnimOut->release();
} CardSprite* CardSprite::create(const char* inCardImageName, const char* outCardImageName, float duration)
{
CardSprite *pSprite = new CardSprite();
if (pSprite && pSprite->init(inCardImageName, outCardImageName, duration))
{
pSprite->autorelease();
return pSprite;
}
CC_SAFE_DELETE(pSprite);
return NULL;
} bool CardSprite::init(const char* inCardImageName, const char* outCardImageName, float duration)
{
if (!CCSprite::init())
{
return false;
}
initData(inCardImageName, outCardImageName, duration);
return true;
} #pragma mark - initData
void CardSprite::initData(const char* inCardImageName, const char* outCardImageName, float duration)
{
m_isOpened = false; CCSprite* inCard = CCSprite::create(inCardImageName);
inCard->setPosition(CCPointZero);
inCard->setVisible(false);
inCard->setTag(tag_inCard);
addChild(inCard); CCSprite* outCard = CCSprite::create(outCardImageName);
outCard->setPosition(CCPointZero);
outCard->setTag(tag_outCard);
addChild(outCard); m_openAnimIn = (CCActionInterval*)CCSequence::create(CCDelayTime::create(duration * .),
CCShow::create(),
CCOrbitCamera::create(duration * ., , , kInAngleZ, kInDeltaZ, , ),
NULL);
m_openAnimIn->retain(); m_openAnimOut = (CCActionInterval *)CCSequence::create(CCOrbitCamera::create(duration * ., , , kOutAngleZ, kOutDeltaZ, , ),
CCHide::create(),
CCDelayTime::create(duration * .),
NULL);
m_openAnimOut->retain();
} #pragma mark - public func
void CardSprite::openCard()
{
CCSprite* inCard = (CCSprite*)getChildByTag(tag_inCard);
CCSprite* outCard = (CCSprite*)getChildByTag(tag_outCard);
inCard->runAction(m_openAnimIn);
outCard->runAction(m_openAnimOut);
}