在炸金花游戏中, 有个看牌动作:三张反面牌经翻转180度后,显示牌面,用动作解体这个过程:
初始化三张牌及牌点---->设置翻牌前的Zorder ---->(从0到90翻转同时所有牌的中心点向第一张牌位置靠近直至重合)--->更改所有牌的牌点(更换显示帧)--->设置牌点显示时的Zorder--->从90到180度翻转同时所有牌移动到自己的位置----->动作结束回调。
例:
void MyTest_1::runActionReverse()
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCPoint pt_0;
for(int i = 0; i < CARDNUM ; i ++)
{
CCSprite* pSprite = CCSprite::spriteWithFile("send_card_1.png"); // 反面时的显示帧一样
pSprite->setPosition( ccp(size.width/2 + i * 20, size.height/2) );// 20为牌间距
this->addChild(pSprite,CARDNUM - i - 1, i + Tag_CardStart); // CARDNUM 为宏 当前牌数3
if(0 == i)
{
pt_0 = pSprite->getPosition();
pSprite->runAction( CCSequence::actions(CCDelayTime::create(1),
CCOrbitCamera::actionWithDuration(0.5 , 1 , 0 , 0 , 90 , 0, 0), // 翻转90度
CCCallFuncND::actionWithTarget(this , callfuncND_selector(MyTest_1::objectReset), (void*)i) , // 重置显示帧及Zorder
CCOrbitCamera::actionWithDuration(0.5 , -1 , 0 , 90, 90 , 0, 0), NULL));
}
else
{
pSprite->runAction( CCSequence::actions(CCDelayTime::create(1),
CCSpawn::create(CCOrbitCamera::actionWithDuration(0.5 , 1 , 0 , 0 , 90 , 0, 0),
CCMoveTo::create(0.5, ccp(pt_0.x - 20 * i, pt_1.y)), NULL),
CCCallFuncND::actionWithTarget(this , callfuncND_selector(MyTest_1::objectReset), (void*)i),
CCSpawn::create(CCOrbitCamera::actionWithDuration(0.5 , -1 , 0 , 90, 90 , 0, 0), CCMoveTo::create(0.5, pt_1), NULL), NULL));
}
}
}
// 90度时的回调函数
void MyTest_1::objectReset(CCNode* pSender, void* param)
{
int nIndex = (int) param;
// 通过下标取得牌点 及所对应的纹理 略
CCSprite *sprite = (CCSprite *)pSender;
if(NULL != sprite)
{
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("poker_XX.png");
if (texture)
{
sprite -> setTexture(texture);
if (sprite->getParent())
{
sprite->getParent()->reorderChild(sprite, zorder); // 显示时牌的Zorder
}
}
}
}
可在runAction时加翻转结束的回调, 做回收及状态更改通知。