cocos2dx实现翻书效果

转载备用,后面项目需要用。

http://blog.csdn.net/goichunhye11/article/details/50825126


因为项目需求,需要使用cocos实现3d翻书的效果,刚开始确实没有什么思路,cocos2d做3d的效果这不是开玩笑吗。但是,再难也得做啊,没办法。

开始查资料,在百度,google上搜索了好几天,基本把所有的文章都翻遍了,根本没有人实现过,好吧,我承认有点虚了,这可咋办。

后来想到cocos2dx的例子里有个类似的效果,不过那个是个action,后来看了看感觉还可以,只是效果和我的需求有点差异,但终归是找到了实现的思路,于是开始看cocos2dx的源码,主要用到的是cocos的网格动画,涉及到以下几个文件:

CCGrid.h /cpp :网格数据及渲染,包括基本网格数据和3D网格数据,这是数据的基础。

CCActionGrid.h /cpp :网格基本动画,这是动画的基础。

CCActionGrid3D.h/cpp: 3D网格基本动画,这是3D网格动画的基础。

CCActionTiledGrid.h / cpp :网格衍生动画,这是最终的特效实现。

咱们这里主要用到CCGrid.h进行渲染,其他三个是action的实现。


这里插一句,在此之前,我曾经还想用遮罩去实现类似的翻书效果,因为android上类似效果的实现就是实用遮罩的,可是在cocos中这种方法行不通,最终放弃了。


看CCActionPageTurn3d这个类,cocos的翻页效果的实现就是在这个类中实现的,在这个类中有个update()函数:

/*

 * Update each tick

 * Time is the percentage of the way through the duration

 */

voidCCPageTurn3D::update(float time)

{

    float tt =MAX(0, time -0.25f);

[html]  view plain  copy
  1. #include "BoluPageTurn2.h"  
  2. #include "BoluButton.h"  
  3. #include "../BoluMsg/BoluMsgPick.h"  
  4. #include "../BoluStage.h"  
  5. #include "../BoluGame/BoluPropNm.h"  
  6. #include "../BoluPlay/BoluMngTable.h"  
  7. #include "RoundProgress.hpp"  
  8. #include "../BoluUserCfg.h"  
  9.   
  10. #define FLIP_CARD_NUM "FLIPCARDNUM"  
  11.   
  12. SuitPosInfo PageTurn2::pos[] = {{60,400,0},{60,263,0},{60,128,0}};  
  13.   
  14. // implementation of PageTurn2  
  15. PageTurn2::PageTurn2(void):  
  16. m_pForeSprite(NULL),  
  17. m_pBgSprite(NULL),  
  18. m_pBgSpriteMirror(NULL),  
  19. m_pForeSpriteMirror(NULL),  
  20. m_pForeSpriteVertical(NULL),  
  21. m_pBgSpriteVertical(NULL),  
  22. m_pBgSpriteMirrorVertical(NULL),  
  23. m_pForeSpriteMirrorVertical(NULL),  
  24. //pHorizontalItem(NULL),  
  25. //pVerticalAItem(NULL),  
  26. //pVerticalEItem(NULL),  
  27. m_pShowPokerCard(NULL),  
  28. mpHideBtn(nullptr),  
  29. mpMenu(nullptr),  
  30. mpAlarmLabel(nullptr),  
  31. mCurLyr(nullptr)  
  32. {  
  33.     EventManager::sharedEventManager()->addObserver(this);  
  34. }  
  35.   
  36. PageTurn2::~PageTurn2(void)  
  37. {  
  38.     EventManager::sharedEventManager()->removeObserver(this);  
  39. }  
  40.   
  41. bool PageTurn2::init(const PickHAry &ary,int nTableId,int nLeftTime)  
  42. {  
  43.     bool bRet = false;  
  44.     do  
  45.     {  
  46.         CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();  
  47.         CCSize winSize = CCDirector::sharedDirector()->getWinSize();  
  48.         setContentSize(winSize);  
  49.         int num = GetRayInt(FLIP_CARD_NUM,0);  
  50.         if (num < 3) {  
  51.             num++;  
  52.             SetRayInt(FLIP_CARD_NUM, num);  
  53.             NtfShowTipsA("{0xFF0000亲,在设置-系统设置中可关闭或开启搓牌哦}");  
  54.         }  
  55.         mPickAry = ary;  
  56.         mNLeftTM = nLeftTime;  
  57.           
  58.         mTableId = nTableId;  
  59.         mCurIndex = g_stage->mFlipProgress[mTableId];  
  60.           
  61.         CCLayerColor* pBgLayer = CCLayerColor::create(ccc4(0, 0, 0, 125));  
  62.         pBgLayer->setContentSize(winSize);  
  63.         pBgLayer->setAnchorPoint(ccp(0, 0));  
  64.         pBgLayer->setPosition(ccp(0, 0));  
  65.         addChild(pBgLayer);  
  66.           
  67.         CCSprite* pBgSprite = NtfCreateSprite("FarmAndPine/flip_left_bg.png");  
  68.         pBgSprite->setAnchorPoint(ccp(0, 0.5));  
  69.         pBgSprite->setPosition(ccp(0, winSize.height/2));  
  70.         this->addChild(pBgSprite);  
  71.           
  72.         for (int i = 0; i < mPickAry.size(); i++) {  
  73.             if (mCurIndex > i)  
  74.             {  
  75.                 String imgName = GetCardFace(mPickAry[i].mGrp, mPickAry[i].mNum);  
  76.                 CCSprite* sprite = NtfCreateSprite(imgName.c_str());  
  77.                 sprite->setPosition(ccp(pos[i].fx,pos[i].fy));  
  78.                 this->addChild(sprite,1,i);  
  79.             }  
  80.             else if (mCurIndex == i) {  
  81.                 cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/fanpaidonghuazuixin0.png", "BuilderAnimate/fanpaidonghuazuixin0.plist", "BuilderAnimate/fanpaidonghuazuixin.ExportJson");  
  82.                 CCArmature* armatureTriangle = cocos2d::extension::CCArmature::create("fanpaidonghuazuixin");  
  83.                 armatureTriangle->setAnchorPoint(ccp(0.5, 0.5));  
  84.                 armatureTriangle->setPosition(ccp(pos[i].fx, pos[i].fy));  
  85.                 armatureTriangle->getAnimation()->playWithIndex(0);  
  86.                 this->addChild(armatureTriangle,1,mCurIndex);  
  87.             }  
  88.             else  
  89.             {  
  90.                  
  91.                 CCSprite* sprite = NtfCreateSprite("SmallImg/bkg_playboard06.png");  
  92.                 sprite->setPosition(ccp(pos[i].fx, pos[i].fy));  
  93.                 this->addChild(sprite,1,i);  
  94.                   
  95.             }  
  96.         }  
  97.         m_sGridSize = CCSizeMake(50, 50);  
  98.           
  99.         createPokerSprite(ary[mCurIndex].mGrp,ary[mCurIndex].mNum);  
  100.           
  101.           
  102.           
  103.           
  104.           
  105.         // 玩家头像  
  106.         String sImg = g_pSelf->GetSelfIcon();  
  107.         if (sImg.empty())  
  108.             sImg = "ImgIcon/bkgIconCircle01.png";  
  109.           
  110.         CCClippingNode* clipA = NtfSetHeadIcon(sImg.c_str(), CCSize(56, 56));  
  111.         clipA->setAnchorPoint(ccp(0.5, 0.5));  
  112.         clipA->setPosition(ccp(60, winSize.height - 118));  
  113.         this->addChild(clipA, 30,TAG_AVATAR);  
  114.           
  115.           
  116.         //搓牌倒计时  
  117.         CCSprite* pTimerBg = NtfCreateSprite("SmallImg/bkg_pic_Other.png");  
  118.         pTimerBg->setAnchorPoint(ccp(0.5, 0.5));  
  119.         pTimerBg->setPosition(ccp(60, winSize.height - 118));  
  120.         addChild(pTimerBg);  
  121.           
  122.         g_stage->DisplayAvatar(g_pSelf->GetValue(RVT_ACC_ID), 0);  
  123.           
  124.           
  125.           
  126.         std::stringstream s;  
  127.         s << mNLeftTM;  
  128.           
  129.         CCNode *vNd = AddNumImg(atoi(s.str().c_str()), 10);  
  130.         vNd->setPosition(ccp(60, winSize.height - 118));  
  131.         vNd->setAnchorPoint(ccp(0.5, 0.5));  
  132.         this->addChild(vNd, 60,TAG_TIMER);  
  133. //        mpAlarmLabel = CCLabelTTF::create(s.str().c_str(), "", 22, CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);  
  134. //        mpAlarmLabel->setPosition(ccp(60, winSize.height - 118));  
  135. //        mpAlarmLabel->setAnchorPoint(ccp(0.5, 0.5));  
  136. //        this->addChild(mpAlarmLabel,60);  
  137.           
  138.         schedule(schedule_selector(PageTurn2::onAlarmUpdate), 1.0f, mNLeftTM, 0.0f);  
  139.           
  140.         mFlipDemoOffset = 0;  
  141.         schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  142.           
  143.         RoundProgress* pProgress = RoundProgress::create();  
  144.         pProgress->setAnchorPoint(ccp(0.5, 0.5));  
  145.         pProgress->setPosition(ccp(pTimerBg->getContentSize().width/2,pTimerBg->getContentSize().height/2));  
  146.         pTimerBg->addChild(pProgress, 190);  
  147.         pProgress->start(mNLeftTM);  
  148.           
  149.         //横置按钮  
  150.         SEL_MenuHandler rotate = menu_selector(PageTurn2::OnClickHorizontal);  
  151.         CRayButton *pRotateBtn = CRayButton::create("FarmAndPine/btn_rotate_normal.png", "FarmAndPine/btn_rotate_selected.png", NULL);  
  152.         pRotateBtn->AttachHandler(this, rotate);  
  153.         pRotateBtn->setPosition(ccp(origin.x + winSize.width - pRotateBtn->getContentSize().width / 2 - 100,  
  154.                                   origin.y + pRotateBtn->getContentSize().height / 2 + 120));  
  155.         pRotateBtn->EnableAnima(false);  
  156.         this->addChild(pRotateBtn);  
  157.         mTouchLyr.push_back(pRotateBtn);  
  158.           
  159.         //开牌按钮  
  160.         SEL_MenuHandler flip = menu_selector(PageTurn2::OnClickFlip);  
  161.         CRayButton *pFlipBtn = CRayButton::create("FarmAndPine/btn_flipcard_normal.png", "FarmAndPine/btn_flipcard_selected.png", NULL);  
  162.         pFlipBtn->AttachHandler(this, flip);  
  163.         pFlipBtn->setPosition(ccp(origin.x + winSize.width - pFlipBtn->getContentSize().width / 2 - 100,  
  164.                                     origin.y + pFlipBtn->getContentSize().height / 2 + 420));  
  165.         pFlipBtn->EnableAnima(false);  
  166.         this->addChild(pFlipBtn,5);  
  167.         mTouchLyr.push_back(pFlipBtn);  
  168.           
  169.         mpHideBtn = CCControlButton::create("", "", 26);  
  170.         mpHideBtn->setBackgroundSpriteForState(CCScale9Sprite::create("FarmAndPine/btn_hide_card_normal.png"), CCControlStateNormal);  
  171.         mpHideBtn->setBackgroundSpriteForState(CCScale9Sprite::create("FarmAndPine/btn_hide_card_selected.png"), CCControlStateHighlighted);  
  172.         mpHideBtn->setAnchorPoint(ccp(0.5, 0.5));  
  173.         mpHideBtn->setPosition(ccp(origin.x + winSize.width - mpHideBtn->getContentSize().width/2 - 95,  
  174.                                     origin.y + mpHideBtn->getContentSize().height/2 + 370));  
  175.         mpHideBtn->setContentSize(CCSizeMake(105, 90));  
  176.         mpHideBtn->setPreferredSize(CCSizeMake(105, 90));  
  177.         mpHideBtn->setZoomOnTouchDown(false);  
  178.         addChild(mpHideBtn,100);  
  179.           
  180.         // 按下按钮事件回调  
  181.         mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchDownAction), CCControlEventTouchDown);  
  182.         // 按钮在其内部拾起事件回调  
  183.         mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchUpInsideAction), CCControlEventTouchUpInside);  
  184.         //按钮在其外部拾起事件回调  
  185.         mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchUpOutsideAction), CCControlEventTouchUpOutside);  
  186.           
  187.         if (mCurIndex == mPickAry.size()) {  
  188.             mbIsFliped = true;  
  189.             mFlipDemoOffset = 0;  
  190.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  191.             m_pForeSprite->setVisible(false);  
  192.             m_pForeSpriteMirror->setVisible(false);  
  193.             m_pBgSprite->setVisible(false);  
  194.             m_pBgSpriteMirror->setVisible(false);  
  195.             //添加盘牌动画  
  196.             m_pShowPokerCard = createPokerCard(mPickAry[mCurIndex-1].mGrp, mPickAry[mCurIndex-1].mNum,true);  
  197.             m_pShowPokerCard->setAnchorPoint(ccp(0.5, 0.5));  
  198.             m_pShowPokerCard->setPosition(ccp(winSize.width/2, winSize.height/2));  
  199.             this->addChild(m_pShowPokerCard,2);  
  200.               
  201.             scheduleOnce(schedule_selector(PageTurn2::onRemoveUpdate), 2);  
  202.         }  
  203.           
  204.         bRet = true;  
  205.     }  
  206.     while (0);  
  207.     return bRet;  
  208. }  
  209.   
  210. void PageTurn2::onRemoveUpdate(float ft)  
  211. {  
  212.     g_stage->mFlipProgress[mTableId] = 0;  
  213.     removeFromParentAndCleanup(true);  
  214.     EventManager::sharedEventManager()->notifyEventFinished(EventShowLastThreeCard);  
  215.   
  216. }  
  217.   
  218. void PageTurn2::onTouchDownAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)  
  219. {  
  220.     if (!mbIsFliped) {  
  221.           
  222.         if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  223.             mFlipDemoOffset = 0;  
  224.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  225.             m_pForeSprite->setVisible(false);  
  226.             m_pForeSpriteMirror->setVisible(false);  
  227.             m_pBgSprite->setVisible(false);  
  228.             m_pBgSpriteMirror->setVisible(false);  
  229.         }  
  230.         else  
  231.         {  
  232.             m_pForeSpriteVertical->setVisible(false);  
  233.             m_pForeSpriteMirrorVertical->setVisible(false);  
  234.             m_pBgSpriteVertical->setVisible(false);  
  235.             m_pBgSpriteMirrorVertical->setVisible(false);  
  236.         }  
  237.     }  
  238.       
  239.       
  240. }  
  241.   
  242. void PageTurn2::onTouchUpInsideAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)  
  243. {  
  244.     if (!mbIsFliped) {  
  245.           
  246.         if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  247.             mFlipDemoOffset = 0;  
  248.             schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  249.             m_pForeSprite->setVisible(false);  
  250.             m_pForeSpriteMirror->setVisible(true);  
  251.             m_pBgSprite->setVisible(false);  
  252.             m_pBgSpriteMirror->setVisible(true);  
  253.         }  
  254.         else  
  255.         {  
  256.             m_pForeSpriteVertical->setVisible(false);  
  257.             m_pForeSpriteMirrorVertical->setVisible(true);  
  258.             m_pBgSpriteVertical->setVisible(false);  
  259.             m_pBgSpriteMirrorVertical->setVisible(true);  
  260.         }  
  261.     }  
  262.       
  263. }  
  264.   
  265. void PageTurn2::onTouchUpOutsideAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)  
  266. {  
  267.     if (!mbIsFliped) {  
  268.           
  269.         if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  270.             mFlipDemoOffset = 0;  
  271.             schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  272.             m_pForeSprite->setVisible(false);  
  273.             m_pForeSpriteMirror->setVisible(true);  
  274.             m_pBgSprite->setVisible(false);  
  275.             m_pBgSpriteMirror->setVisible(true);  
  276.         }  
  277.         else  
  278.         {  
  279.             m_pForeSpriteVertical->setVisible(false);  
  280.             m_pForeSpriteMirrorVertical->setVisible(true);  
  281.             m_pBgSpriteVertical->setVisible(false);  
  282.             m_pBgSpriteMirrorVertical->setVisible(true);  
  283.         }  
  284.     }  
  285.       
  286. }  
  287.   
  288. void PageTurn2::createPokerSprite(CCrdGrp type, CCrdNum num)  
  289. {  
  290.     //水平牌  
  291.     m_pForeSprite = createPokerCard(type, num,false);  
  292.     m_pForeSprite->setAnchorPoint(ccp(0.5, 0.5));  
  293.     m_pForeSprite->setPosition(ccp(m_pForeSprite->getContentSize().width/2, m_pForeSprite->getContentSize().height/2));  
  294.     m_pForeSprite->setFlipX(true);  
  295.     this->addChild(m_pForeSprite,2);  
  296.     m_pForeSprite->setVisible(false);  
  297.       
  298.     m_pForeSpriteMirror = createPokerCard(type, num,false);  
  299.     m_pForeSpriteMirror->setAnchorPoint(ccp(0.5, 0.5));  
  300.     m_pForeSpriteMirror->setPosition(ccp(mHOffsetX + m_pForeSpriteMirror->getContentSize().width/2,mHOffsetY + m_pForeSpriteMirror->getContentSize().height/2));  
  301.     this->addChild(m_pForeSpriteMirror);  
  302.       
  303.     m_pBgSprite = NtfCreateSprite("Cards/card_bg.png");  
  304.     m_pBgSprite->setAnchorPoint(ccp(0.5, 0.5));  
  305.     m_pBgSprite->setPosition(ccp(m_pBgSprite->getContentSize().width/2, m_pBgSprite->getContentSize().height/2));  
  306.     this->addChild(m_pBgSprite,1);  
  307.     m_pBgSprite->setVisible(false);  
  308.       
  309.     m_pBgSpriteMirror = NtfCreateSprite("Cards/card_bg.png");  
  310.     m_pBgSpriteMirror->setAnchorPoint(ccp(0.5, 0.5));  
  311.     m_pBgSpriteMirror->setPosition(ccp(mHOffsetX + m_pBgSpriteMirror->getContentSize().width/2,mHOffsetY + m_pBgSpriteMirror->getContentSize().height/2));  
  312.     this->addChild(m_pBgSpriteMirror);  
  313.       
  314.     //竖直牌  
  315.     m_pForeSpriteVertical = createPokerCard(type, num,false);  
  316.     m_pForeSpriteVertical->setAnchorPoint(ccp(0.5, 0.5));  
  317.     m_pForeSpriteVertical->setPosition(ccp(m_pForeSpriteVertical->getContentSize().height/2 ,m_pForeSpriteVertical->getContentSize().width/2));  
  318.     m_pForeSpriteVertical->setFlipX(true);  
  319.     this->addChild(m_pForeSpriteVertical,2);  
  320.     m_pForeSpriteVertical->setVisible(false);  
  321.     m_pForeSpriteVertical->setRotation(90);  
  322.       
  323.     m_pForeSpriteMirrorVertical = createPokerCard(type, num,false);  
  324.     m_pForeSpriteMirrorVertical->setAnchorPoint(ccp(0.5, 0.5));  
  325.     m_pForeSpriteMirrorVertical->setPosition(ccp(mVOffsetX + m_pForeSpriteMirrorVertical->getContentSize().height/2 ,mVOffsetY + m_pForeSpriteMirrorVertical->getContentSize().width/2));  
  326.     this->addChild(m_pForeSpriteMirrorVertical);  
  327.     m_pForeSpriteMirrorVertical->setRotation(90);  
  328.       
  329.       
  330.     m_pBgSpriteVertical = NtfCreateSprite("Cards/card_bg.png");  
  331.     m_pBgSpriteVertical->setAnchorPoint(ccp(0.5, 0.5));  
  332.     m_pBgSpriteVertical->setPosition(ccp(m_pBgSpriteVertical->getContentSize().height/2 ,m_pBgSpriteVertical->getContentSize().width/2));  
  333.     this->addChild(m_pBgSpriteVertical,1);  
  334.     m_pBgSpriteVertical->setVisible(false);  
  335.     m_pBgSpriteVertical->setRotation(90);  
  336.       
  337.     m_pBgSpriteMirrorVertical = NtfCreateSprite("Cards/card_bg.png");  
  338.     m_pBgSpriteMirrorVertical->setAnchorPoint(ccp(0.5, 0.5));  
  339.     m_pBgSpriteMirrorVertical->setPosition(ccp(mVOffsetX + m_pBgSpriteMirrorVertical->getContentSize().height/2 ,mVOffsetY + m_pBgSpriteMirrorVertical->getContentSize().width/2));  
  340.     this->addChild(m_pBgSpriteMirrorVertical);  
  341.     m_pBgSpriteMirrorVertical->setRotation(90);  
  342.       
  343.       
  344.     if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  345.         m_pForeSpriteVertical->setVisible(false);  
  346.         m_pForeSpriteMirrorVertical->setVisible(false);  
  347.         m_pBgSpriteVertical->setVisible(false);  
  348.         m_pBgSpriteMirrorVertical->setVisible(false);  
  349.     }  
  350.       
  351. //    cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/cuowo-triangle0.png", "BuilderAnimate/cuowo-triangle0.plist", "BuilderAnimate/cuowo-triangle.ExportJson");  
  352. //    CCArmature* armatureTriangle = cocos2d::extension::CCArmature::create("cuowo-triangle");  
  353. //    armatureTriangle->setAnchorPoint(ccp(1, 0));  
  354. //    armatureTriangle->setPosition(ccp(m_pBgSprite->getContentSize().width, 0));  
  355. //    armatureTriangle->getAnimation()->playWithIndex(0);  
  356. //    m_pBgSpriteMirror->addChild(armatureTriangle);  
  357. //      
  358. //      
  359. //    cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/cuopai0.png", "BuilderAnimate/cuopai0.plist", "BuilderAnimate/cuopai.ExportJson");  
  360. //    CCArmature* armature = cocos2d::extension::CCArmature::create("cuopai");  
  361. //    armature->setAnchorPoint(ccp(0, 0));  
  362. //    armature->setPosition(ccp(m_pBgSprite->getContentSize().width, 0));  
  363. //    armature->setRotation(-90);  
  364. //    armature->getAnimation()->playWithIndex(0);  
  365. //    m_pBgSpriteMirrorVertical->addChild(armature);  
  366. //      
  367. //    CCArmature* armature2 = cocos2d::extension::CCArmature::create("cuopai");  
  368. //    armature2->setAnchorPoint(ccp(0, 0));  
  369. //    armature2->setPosition(ccp(0, m_pBgSprite->getContentSize().height));  
  370. //    armature2->setRotation(90);  
  371. //    armature2->getAnimation()->playWithIndex(0);  
  372. //    m_pBgSpriteMirrorVertical->addChild(armature2);  
  373.       
  374.     startWithTarget(m_pForeSprite,true,m_pForeSprite->getContentSize());  
  375.     startWithTarget(m_pBgSprite,false,m_pBgSprite->getContentSize());  
  376.       
  377.     startWithTarget(m_pForeSpriteVertical, true, CCSizeMake(m_pForeSpriteVertical->getContentSize().height, m_pForeSpriteVertical->getContentSize().width));  
  378.     startWithTarget(m_pBgSpriteVertical, false, CCSizeMake(m_pBgSpriteVertical->getContentSize().height, m_pBgSpriteVertical->getContentSize().width));  
  379. }  
  380.   
  381.   
  382. void PageTurn2::onAlarmUpdate(float ft)  
  383. {  
  384.     CCSize winSize = CCDirector::sharedDirector()->getWinSize();  
  385.     CCNode* pNode = getChildByTag(TAG_TIMER);  
  386.     if (pNode) {  
  387.         pNode->removeFromParent();  
  388.           
  389.         mNLeftTM--;  
  390.         if (mNLeftTM <= 0) {  
  391.             OnClickFlip(nullptr);  
  392.             unschedule(schedule_selector(PageTurn2::onAlarmUpdate));  
  393.         }  
  394.         std::stringstream s;  
  395.         s << mNLeftTM;  
  396.         CCNode *vNd = AddNumImg(atoi(s.str().c_str()), 10);  
  397.         vNd->setPosition(ccp(60, winSize.height - 118));  
  398.         vNd->setAnchorPoint(ccp(0.5, 0.5));  
  399.         this->addChild(vNd, 60,TAG_TIMER);  
  400.           
  401.     }  
  402. //    if (mpAlarmLabel) {  
  403. //        mNLeftTM--;  
  404. //        if (mNLeftTM <= 0) {  
  405. //            OnClickFlip(nullptr);  
  406. //            unschedule(schedule_selector(PageTurn2::onAlarmUpdate));  
  407. //        }  
  408. //        std::stringstream s;  
  409. //        s << mNLeftTM;  
  410. //          
  411. //          
  412. //        mpAlarmLabel->setString(s.str().c_str());  
  413. //    }  
  414. }  
  415.   
  416. void PageTurn2::onFlipDemoUpdate(float ft)  
  417. {  
  418.     if (mFlipDemoOffset > 100) {  
  419.         isIncrease = false;  
  420.     }  
  421.     else if(mFlipDemoOffset <= 0)  
  422.     {  
  423.         isIncrease = true;  
  424.     }  
  425.     if (isIncrease)  
  426.     {  
  427.         mFlipDemoOffset += 2;  
  428.     }  
  429.     else  
  430.     {  
  431.         mFlipDemoOffset -2;;  
  432.     }  
  433.       
  434.     if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  435.         if (!m_pBgSprite->isVisible()) {  
  436.             m_pBgSprite->setVisible(true);  
  437.             m_pBgSpriteMirror->setVisible(false);  
  438.         }  
  439.         if (!m_pForeSprite->isVisible()) {  
  440.             m_pForeSprite->setVisible(true);  
  441.             m_pForeSpriteMirror->setVisible(false);  
  442.         }  
  443.     }  
  444.     else  
  445.     {  
  446.         if (!m_pBgSpriteVertical->isVisible()) {  
  447.             m_pBgSpriteVertical->setVisible(true);  
  448.             m_pBgSpriteMirrorVertical->setVisible(false);  
  449.         }  
  450.         if (!m_pForeSpriteVertical->isVisible()) {  
  451.             m_pForeSpriteVertical->setVisible(true);  
  452.             m_pForeSpriteMirrorVertical->setVisible(false);  
  453.         }  
  454.     }  
  455.       
  456.       
  457.     calculateHorizontalVertexPoints(mFlipDemoOffset / cosf(M_PI / 4),true);  
  458. }  
  459.   
  460. PageTurn2* PageTurn2::create(const PickHAry &ary,int nTableId,int nLeftTime)  
  461. {  
  462.     PageTurn2 * pRet = new PageTurn2();  
  463.     if (pRet && pRet->init(ary,nTableId,nLeftTime))  
  464.     {  
  465.         pRet->autorelease();  
  466.     }  
  467.     else  
  468.     {  
  469.         CC_SAFE_DELETE(pRet);  
  470.     }  
  471.     return pRet;  
  472. }  
  473.   
  474.   
  475.   
  476.   
  477. MyGrid3D* PageTurn2::getGrid(bool bReverse,const CCSize& size)  
  478. {  
  479.     return MyGrid3D::create(m_sGridSize,size,bReverse);  
  480. }  
  481.   
  482. void PageTurn2::startWithTarget(CCNode *pTarget, bool bReverse, const CCSize& size)  
  483. {  
  484.       
  485.     CCGridBase *newgrid = this->getGrid(bReverse,size);  
  486.       
  487.     CCNode *t = pTarget;  
  488.     CCGridBase *targetGrid = t->getGrid();  
  489.       
  490.     if (targetGrid && targetGrid->getReuseGrid() > 0)  
  491.     {  
  492.         if (targetGrid->isActive() && targetGrid->getGridSize().width == m_sGridSize.width  
  493.             && targetGrid->getGridSize().height == m_sGridSize.height /*&& dynamic_cast<CCGridBase*>(targetGrid) != NULL*/)  
  494.         {  
  495.             targetGrid->reuse();  
  496.         }  
  497.         else  
  498.         {  
  499.             CCAssert(0, "");  
  500.         }  
  501.     }  
  502.     else  
  503.     {  
  504.         if (targetGrid && targetGrid->isActive())  
  505.         {  
  506.             targetGrid->setActive(false);  
  507.         }  
  508.           
  509.         t->setGrid(newgrid);  
  510.         t->getGrid()->setActive(true);  
  511.     }  
  512. }  
  513.   
  514. ccVertex3F PageTurn2::vertex(const CCPoint& position,CCNode *pTarget)  
  515. {  
  516.     CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();  
  517.     return g->vertex(position);  
  518. }  
  519.   
  520. ccVertex3F PageTurn2::originalVertex(const CCPoint& position,CCNode *pTarget)  
  521. {  
  522.     CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();  
  523.     return g->originalVertex(position);  
  524. }  
  525.   
  526. void PageTurn2::setVertex(const CCPoint& position, const ccVertex3F& vertex,CCNode *pTarget)  
  527. {  
  528.     CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();  
  529.     g->setVertex(position, vertex);  
  530. }  
  531.   
  532. void PageTurn2::registerWithTouchDispatcher()  
  533. {  
  534. //    CCDirector* pDirec = CCDirector::sharedDirector();  
  535. //    pDirec->getTouchDispatcher()->addTargetedDelegate(this, 0, true);  
  536. }  
  537.   
  538. bool PageTurn2::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)  
  539. {  
  540.     CCPoint point = pTouch->getLocation();  
  541.     CCSize winSize = CCDirector::sharedDirector()->getWinSize();  
  542.       
  543.     float borderXH = winSize.width/2 + m_pBgSprite->getContentSize().width/2;  
  544.     float borderYH = winSize.height/2 - m_pBgSprite->getContentSize().height/2;  
  545.     float borderXHMin = winSize.width/2 - m_pBgSprite->getContentSize().width/2;  
  546.       
  547.     float borderXVMax = winSize.width/2 + m_pBgSprite->getContentSize().height/2;  
  548.     float borderXVMin = winSize.width/2 - m_pBgSprite->getContentSize().height/2;  
  549.     float borderYV = mVOffsetY;  
  550.       
  551.     if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  552.         if (point.x > borderXH - 150 && point.x < borderXH && point.y > borderYH && point.y < borderYH + 150)  
  553.         {  
  554.             //触摸牌的右下角  
  555.             mTouchBegin = pTouch->getLocation();  
  556.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  557.         }  
  558.         else if (point.x > borderXHMin && point.x < borderXHMin + 150 && point.y > borderYH && point.y < borderYH + 150)  
  559.         {//触摸牌的左下角  
  560.             mTouchBegin = pTouch->getLocation();  
  561.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  562.         }  
  563.         else  
  564.         {  
  565.             mTouchBegin = CCPoint(0, 0);  
  566.         }  
  567.     }  
  568.     else  
  569.     {  
  570.         if (point.x > borderXVMin && point.x < borderXVMax && point.y > borderYV && point.y < borderYV + 150)  
  571.         {  
  572.             //垂直情况下触摸牌的下边缘  
  573.             mTouchBegin = pTouch->getLocation();  
  574.         }  
  575.         else  
  576.         {  
  577.             mTouchBegin = CCPoint(0, 0);  
  578.         }  
  579.     }  
  580.       
  581.       
  582.     return false;  
  583. }  
  584.   
  585. void PageTurn2::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)  
  586. {  
  587.     if (mTouchBegin.x != 0 && mTouchBegin.y != 0 && !mbIsFliped) {  
  588.         if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  589.             if (!m_pBgSprite->isVisible()) {  
  590.                 m_pBgSprite->setVisible(true);  
  591.                 m_pBgSpriteMirror->setVisible(false);  
  592.             }  
  593.             if (!m_pForeSprite->isVisible()) {  
  594.                 m_pForeSprite->setVisible(true);  
  595.                 m_pForeSpriteMirror->setVisible(false);  
  596.             }  
  597.         }  
  598.         else  
  599.         {  
  600.             if (!m_pBgSpriteVertical->isVisible()) {  
  601.                 m_pBgSpriteVertical->setVisible(true);  
  602.                 m_pBgSpriteMirrorVertical->setVisible(false);  
  603.             }  
  604.             if (!m_pForeSpriteVertical->isVisible()) {  
  605.                 m_pForeSpriteVertical->setVisible(true);  
  606.                 m_pForeSpriteMirrorVertical->setVisible(false);  
  607.             }  
  608.         }  
  609.           
  610.           
  611.         float offsetX = mTouchBegin.x - pTouch->getLocation().x;  
  612.         float offsetY = pTouch->getLocation().y - mTouchBegin.y;  
  613.         bool flag;  
  614.         if (offsetX > 0) {  
  615.             flag = true;  
  616.         }  
  617.         else  
  618.         {  
  619.             flag = false;  
  620.         }  
  621.           
  622.         float offset = fabs(offsetX) > offsetY ? offsetX : offsetY;  
  623.         calculateHorizontalVertexPoints(offset / cosf(M_PI/4), flag);  
  624.           
  625.         calculateVerticalVertexPoints(offsetY);  
  626.           
  627.         if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  628. //            CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, offsetX);  
  629.             judgeIsFlipCard(fabsf(offsetX) / cosf(M_PI / 4),mCardShowType,true);  
  630.         }  
  631.         else if (mCardShowType == VerticalA || mCardShowType == VerticalE)  
  632.         {  
  633. //            CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, offsetY);  
  634.             judgeIsFlipCard(offsetY / cosf(M_PI / 4),mCardShowType,true);  
  635.         }  
  636.     }  
  637. }  
  638.   
  639. void PageTurn2::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)  
  640. {  
  641.    if (mTouchBegin.x != 0 && mTouchBegin.y != 0 && !mbIsFliped) {  
  642.          
  643.        calculateHorizontalVertexPoints(0,true);  
  644.        calculateVerticalVertexPoints(-mVOffsetY);  
  645.        if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {  
  646. //           CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, 0);  
  647.        }  
  648.        else if (mCardShowType == VerticalA || mCardShowType == VerticalE)  
  649.        {  
  650. //           CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, -mVOffsetY);  
  651.        }  
  652.    }  
  653. }  
  654.   
  655. void PageTurn2::calculateHorizontalVertexPoints(float offsetX,bool flag)  
  656. {  
  657.       
  658.     float R = 50;  
  659.       
  660.     if (flag)  
  661.     {  
  662.         float theta = (GLfloat)(M_PI / 6.0f);  
  663.         float b = (m_pBgSprite->getContentSize().width - offsetX * 1.4f) * sinf(theta);  
  664.           
  665.         for (int i = 0; i <= m_sGridSize.width; ++i)  
  666.         {  
  667.             for (int j = 0; j <= m_sGridSize.height; ++j)  
  668.             {  
  669.                 // Get original vertex  
  670.                 ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSprite);  
  671.                   
  672.                 float x = (p.y + b) / tanf(theta);  
  673.                   
  674.                 float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);  
  675.                 float pivotY = pivotX * tanf(theta) - b;  
  676.                   
  677.                 float l = (p.x - pivotX) / sinf(theta);  
  678.                 float alpha = l / R;  
  679.                 if (l >= 0) {  
  680.                     if (alpha > M_PI) {  
  681.                         p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha - M_PI) * sinf(theta));  
  682.                         p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));  
  683.                         p.z = (GLfloat)(2 * R / 9);  
  684.                     }  
  685.                     else if (alpha <= M_PI)  
  686.                     {  
  687.                         p.x = (GLfloat)(mHOffsetX + pivotX + R * sinf(alpha) * sinf(theta));  
  688.                         p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));  
  689.                         p.z = (GLfloat)((R - R * cosf(alpha)) / 9);  
  690.                     }  
  691.                 }  
  692.                 else  
  693.                 {  
  694.                     p.x += mHOffsetX;  
  695.                     p.y += mHOffsetY;  
  696.                 }  
  697.                   
  698.                 // Set new coords  
  699.                 setVertex(ccp(i, j), p,m_pForeSprite);  
  700.                   
  701.                   
  702.             }  
  703.         }  
  704.           
  705.         for (int i = 0; i <= m_sGridSize.width; ++i)  
  706.         {  
  707.             for (int j = 0; j <= m_sGridSize.height; ++j)  
  708.             {  
  709.                 // Get original vertex  
  710.                 ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSprite);  
  711.                 float x = (p.y + b) / tanf(theta);  
  712.                   
  713.                 float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);  
  714.                 float pivotY = pivotX * tanf(theta) - b;  
  715.                   
  716.                 float l = (p.x - pivotX) / sinf(theta);  
  717.                 float alpha = l / R;  
  718.                 if (l >= 0) {  
  719.                     if (alpha > M_PI) {  
  720.                         p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha - M_PI) * sinf(theta));  
  721.                         p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));  
  722.                         p.z = (GLfloat)(2 * R / 9);  
  723.                     }  
  724.                     else if (alpha <= M_PI)  
  725.                     {  
  726.                         p.x = (GLfloat)(mHOffsetX + pivotX + R * sinf(alpha) * sinf(theta));  
  727.                         p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));  
  728.                         p.z = (GLfloat)((R - R * cosf(alpha)) / 9);  
  729.                     }  
  730.                 }  
  731.                 else  
  732.                 {  
  733.                     p.x += mHOffsetX;  
  734.                     p.y += mHOffsetY;  
  735.                 }  
  736.                   
  737.                 setVertex(ccp(i, j), p,m_pBgSprite);  
  738.                   
  739.                   
  740.                   
  741.             }  
  742.         }  
  743.           
  744.     }  
  745.     else  
  746.     {  
  747.         float theta = (GLfloat)(M_PI / 6.0f);  
  748.         float b = fabsf(offsetX * 0.8f);  
  749.         for (int i = 0; i <= m_sGridSize.width; ++i)  
  750.         {  
  751.             for (int j = 0; j <= m_sGridSize.height; ++j)  
  752.             {  
  753.                 // Get original vertex  
  754.                 ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSprite);  
  755.                   
  756.                 float x = (p.y - b) / -tanf(theta);  
  757.                   
  758.                 float pivotX = p.x + (x - p.x) * sinf(theta) * sinf(theta);  
  759.                 float pivotY = pivotX * -tanf(theta) + b;  
  760.                   
  761.                 float l = (pivotX - p.x) / sinf(theta);  
  762.                 float alpha = l / R;  
  763.                 if (l >= 0) {  
  764.                     if (alpha > M_PI) {  
  765.                         p.x = (GLfloat)(mHOffsetX + pivotX + R * (alpha - M_PI) * sinf(theta));  
  766.                         p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));  
  767.                         p.z = (GLfloat)(2 * R / 9);  
  768.                     }  
  769.                     else if (alpha <= M_PI)  
  770.                     {  
  771.                         p.x = (GLfloat)(mHOffsetX + pivotX - R * sinf(alpha) * sinf(theta));  
  772.                         p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));  
  773.                         p.z = (GLfloat)((R - R * cosf(alpha)) / 9);  
  774.                     }  
  775.                 }  
  776.                 else  
  777.                 {  
  778.                     p.x += mHOffsetX;  
  779.                     p.y += mHOffsetY;  
  780.                 }  
  781.                   
  782.                 // Set new coords  
  783.                 setVertex(ccp(i, j), p,m_pForeSprite);  
  784.                   
  785.                   
  786.             }  
  787.         }  
  788.           
  789.         for (int i = 0; i <= m_sGridSize.width; ++i)  
  790.         {  
  791.             for (int j = 0; j <= m_sGridSize.height; ++j)  
  792.             {  
  793.                 // Get original vertex  
  794.                 ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSprite);  
  795.                   
  796.                 float x = (p.y - b) / -tanf(theta);  
  797.                   
  798.                 float pivotX = p.x + (x - p.x) * sinf(theta) * sinf(theta);  
  799.                 float pivotY = pivotX * -tanf(theta) + b;  
  800.                   
  801.                 float l = (pivotX - p.x) / sinf(theta);  
  802.                 float alpha = l / R;  
  803.                 if (l >= 0) {  
  804.                     if (alpha > M_PI) {  
  805.                         p.x = (GLfloat)(mHOffsetX + pivotX + R * (alpha - M_PI) * sinf(theta));  
  806.                         p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));  
  807.                         p.z = (GLfloat)(2 * R / 9);  
  808.                     }  
  809.                     else if (alpha <= M_PI)  
  810.                     {  
  811.                         p.x = (GLfloat)(mHOffsetX + pivotX - R * sinf(alpha) * sinf(theta));  
  812.                         p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));  
  813.                         p.z = (GLfloat)((R - R * cosf(alpha)) / 9);  
  814.                     }  
  815.                 }  
  816.                 else  
  817.                 {  
  818.                     p.x += mHOffsetX;  
  819.                     p.y += mHOffsetY;  
  820.                 }  
  821.   
  822.                   
  823.                 setVertex(ccp(i, j), p,m_pBgSprite);  
  824.             }  
  825.         }  
  826.     }  
  827.       
  828.       
  829.     //    float R2 = 50;  
  830.     //    float offsetX2 = mTouchBegin.x - pTouch->getLocation().x;  
  831.     //    float pivotX2 = m_pForeSpriteVertical->getContentSize().height - offsetX2;  
  832.     //  
  833.     //  
  834.     //    for (int i = 0; i <= m_sGridSize.width; ++i)  
  835.     //    {  
  836.     //        for (int j = 0; j <= m_sGridSize.height; ++j)  
  837.     //        {  
  838.     //            // Get original vertex  
  839.     //            ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSpriteVertical);  
  840.     //            float l = p.x - pivotX2;  
  841.     //            float alpha = l / R2;  
  842.     //            if (l >= 0) {  
  843.     //                if (alpha > M_PI) {  
  844.     //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);  
  845.     //                    p.z = 2 * R2 / 9;  
  846.     //                    p.y = p.y + mVOffsetY;  
  847.     //                }  
  848.     //                else if (alpha <= M_PI)  
  849.     //                {  
  850.     //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);  
  851.     //                    p.z = (R2 - R2 * cosf(alpha))/9;  
  852.     //                    p.y = p.y + mVOffsetY;  
  853.     //                }  
  854.     //            }  
  855.     //            else  
  856.     //            {  
  857.     //                p.x = p.x + mVOffsetX;  
  858.     //                p.y = p.y + mVOffsetY;  
  859.     //            }  
  860.     //  
  861.     //  
  862.     //            // Set new coords  
  863.     //            setVertex(ccp(i, j), p,m_pForeSpriteVertical);  
  864.     //  
  865.     //  
  866.     //        }  
  867.     //    }  
  868.     //  
  869.     //    for (int i = 0; i <= m_sGridSize.width; ++i)  
  870.     //    {  
  871.     //        for (int j = 0; j <= m_sGridSize.height; ++j)  
  872.     //        {  
  873.     //            // Get original vertex  
  874.     //            ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSpriteVertical);  
  875.     //            float l = p.x - pivotX2;  
  876.     //            float alpha = l / R2;  
  877.     //            if (l >= 0) {  
  878.     //                if (alpha > M_PI) {  
  879.     //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);  
  880.     //                    p.z = 2 * R2 / 9;  
  881.     //                    p.y = p.y + mVOffsetY;  
  882.     //                }  
  883.     //                else if (alpha <= M_PI)  
  884.     //                {  
  885.     //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);  
  886.     //                    p.z = (R2 - R2 * cosf(alpha))/9;  
  887.     //                    p.y = p.y + mVOffsetY;  
  888.     //                }  
  889.     //            }  
  890.     //            else  
  891.     //            {  
  892.     //                p.x = p.x + mVOffsetX;  
  893.     //                p.y = p.y + mVOffsetY;  
  894.     //            }  
  895.     //  
  896.     //            // Set new coords  
  897.     //            setVertex(ccp(i, j), p,m_pBgSpriteVertical);  
  898.     //              
  899.     //              
  900.     //              
  901.     //        }  
  902.     //    }  
  903. }  
  904.   
  905. void PageTurn2::calculateVerticalVertexPoints(float offsetY)  
  906. {  
  907.     float R2 = 50;  
  908.     float pivotY = offsetY + mVOffsetY;  
  909.       
  910.       
  911.     for (int i = 0; i <= m_sGridSize.width; ++i)  
  912.     {  
  913.         for (int j = 0; j <= m_sGridSize.height; ++j)  
  914.         {  
  915.             // Get original vertex  
  916.             ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSpriteVertical);  
  917.             float l = pivotY - p.y;  
  918.             float alpha = l / R2;  
  919.             if (l >= 0) {  
  920.                 if (alpha > M_PI) {  
  921.                     p.z = (GLfloat)(2 * R2 / 9);  
  922.                     p.y = (GLfloat)(mVOffsetY + pivotY + R2 * (alpha - M_PI));  
  923.                     p.x += mVOffsetX;  
  924.                 }  
  925.                 else if (alpha <= M_PI)  
  926.                 {  
  927.                     p.z = (GLfloat)((R2 - R2 * cosf(alpha))/9);  
  928.                     p.y = (GLfloat)(mVOffsetY + pivotY - R2 * sinf(alpha));  
  929.                       
  930.                     p.x += mVOffsetX;  
  931.                 }  
  932.             }  
  933.             else  
  934.             {  
  935.                 p.x += mVOffsetX;  
  936.                 p.y += mVOffsetY;  
  937.             }  
  938.               
  939.               
  940.             // Set new coords  
  941.             setVertex(ccp(i, j), p,m_pForeSpriteVertical);  
  942.               
  943.               
  944.         }  
  945.     }  
  946.       
  947.     for (int i = 0; i <= m_sGridSize.width; ++i)  
  948.     {  
  949.         for (int j = 0; j <= m_sGridSize.height; ++j)  
  950.         {  
  951.             // Get original vertex  
  952.             ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSpriteVertical);  
  953.             float l = pivotY - p.y;  
  954.             float alpha = l / R2;  
  955.             if (l >= 0) {  
  956.                 if (alpha > M_PI) {  
  957.                     p.z = (GLfloat)(2 * R2 / 9);  
  958.                     p.y = (GLfloat)(mVOffsetY + pivotY + R2 * (alpha - M_PI));  
  959.                     p.x += mVOffsetX;  
  960.                 }  
  961.                 else if (alpha <= M_PI)  
  962.                 {  
  963.                     p.z = (GLfloat)((R2 - R2 * cosf(alpha))/9);  
  964.                     p.y = (GLfloat)(mVOffsetY + pivotY - R2 * sinf(alpha));  
  965.                       
  966.                     p.x += mVOffsetX;  
  967.                 }  
  968.             }  
  969.             else  
  970.             {  
  971.                 p.x += mVOffsetX;  
  972.                 p.y += mVOffsetY;  
  973.             }            // Set new coords  
  974.             setVertex(ccp(i, j), p,m_pBgSpriteVertical);  
  975.               
  976.               
  977.               
  978.         }  
  979.     }  
  980. }  
  981.   
  982. void PageTurn2::ccTouchCancelled(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)  
  983. {  
  984.       
  985. }  
  986.   
  987. void PageTurn2::OnEnterEvn(CCNode*)             // 进入动画结束执行的事件  
  988. {  
  989.       
  990. }  
  991. void PageTurn2::OnExitEvn(CCNode*)                  // 退出动画结束执行的事件  
  992. {  
  993.     removeFromParent();  
  994. }  
  995.   
  996. // 返回  
  997. void PageTurn2::OnClickBack(CCObject* pObject)  
  998. {  
  999.     NtfPlayClose();//关闭的音效  
  1000.     removeFromParent();  
  1001. }  
  1002.   
  1003. void PageTurn2::OnClickHorizontal(cocos2d::CCObject *pObject)  
  1004. {  
  1005.     NtfPlayDefBtnSnd();  
  1006.     if (!mbIsFliped) {  
  1007.           
  1008.         if (mCardShowType != Horizontal && mCardShowType == VerticalE) {  
  1009.             mFlipDemoOffset = 0;  
  1010.             schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  1011.             mCardShowType = Horizontal;  
  1012.             m_pForeSprite->setVisible(false);  
  1013.             m_pForeSpriteMirror->setVisible(true);  
  1014.             m_pBgSprite->setVisible(false);  
  1015.             m_pBgSpriteMirror->setVisible(true);  
  1016.   
  1017.             m_pForeSpriteVertical->setVisible(false);  
  1018.             m_pForeSpriteMirrorVertical->setVisible(false);  
  1019.             m_pBgSpriteVertical->setVisible(false);  
  1020.             m_pBgSpriteMirrorVertical->setVisible(false);  
  1021.               
  1022.             m_pForeSprite->setRotation(0);  
  1023.             m_pForeSpriteMirror->setRotation(0);  
  1024.             m_pBgSprite->setRotation(0);  
  1025.             m_pBgSpriteMirror->setRotation(0);  
  1026.   
  1027.         }  
  1028.         else if (mCardShowType == Horizontal)  
  1029.         {  
  1030.             mFlipDemoOffset = 0;  
  1031.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  1032.             mCardShowType = VerticalA;  
  1033.             m_pForeSprite->setVisible(false);  
  1034.             m_pForeSpriteMirror->setVisible(false);  
  1035.             m_pBgSprite->setVisible(false);  
  1036.             m_pBgSpriteMirror->setVisible(false);  
  1037.               
  1038.             m_pForeSpriteVertical->setVisible(false);  
  1039.             m_pForeSpriteMirrorVertical->setVisible(true);  
  1040.             m_pBgSpriteVertical->setVisible(false);  
  1041.             m_pBgSpriteMirrorVertical->setVisible(true);  
  1042.               
  1043.             m_pForeSpriteVertical->setRotation(-90);  
  1044.             m_pForeSpriteMirrorVertical->setRotation(-90);  
  1045.             m_pBgSpriteVertical->setRotation(-90);  
  1046.             m_pBgSpriteMirrorVertical->setRotation(-90);  
  1047.         }  
  1048.         else if (mCardShowType == VerticalA)  
  1049.         {  
  1050.             mFlipDemoOffset = 0;  
  1051.             schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  1052.             mCardShowType = Horizontal2;  
  1053.             m_pForeSprite->setVisible(false);  
  1054.             m_pForeSpriteMirror->setVisible(true);  
  1055.             m_pBgSprite->setVisible(false);  
  1056.             m_pBgSpriteMirror->setVisible(true);  
  1057.               
  1058.             m_pForeSpriteVertical->setVisible(false);  
  1059.             m_pForeSpriteMirrorVertical->setVisible(false);  
  1060.             m_pBgSpriteVertical->setVisible(false);  
  1061.             m_pBgSpriteMirrorVertical->setVisible(false);  
  1062.               
  1063.             m_pForeSprite->setRotation(180);  
  1064.             m_pForeSpriteMirror->setRotation(180);  
  1065.             m_pBgSprite->setRotation(180);  
  1066.             m_pBgSpriteMirror->setRotation(180);  
  1067.               
  1068.         }  
  1069.         else if(mCardShowType == Horizontal2)  
  1070.         {  
  1071.             mFlipDemoOffset = 0;  
  1072.             unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));  
  1073.             mCardShowType = VerticalE;  
  1074.             m_pForeSprite->setVisible(false);  
  1075.             m_pForeSpriteMirror->setVisible(false);  
  1076.             m_pBgSprite->setVisible(false);  
  1077.             m_pBgSpriteMirror->setVisible(false);  
  1078.               
  1079.             m_pForeSpriteVertical->setVisible(false);  
  1080.             m_pForeSpriteMirrorVertical->setVisible(true);  
  1081.             m_pBgSpriteVertical->setVisible(false);  
  1082.             m_pBgSpriteMirrorVertical->setVisible(true);  
  1083.               
  1084.             m_pForeSpriteVertical->setRotation(90);  
  1085.             m_pForeSpriteMirrorVertical->setRotation(90);  
  1086.             m_pBgSpriteVertical->setRotation(90);  
  1087.             m_pBgSpriteMirrorVertical->setRotation(90);  
  1088.         }  
  1089.     }  
  1090.       
  1091. }  
  1092.   
  1093. void PageTurn2::OnClickVerticalA(CCObject* pObject)  
  1094. {  
  1095.     NtfPlayDefBtnSnd();  
  1096.     if (!mbIsFliped) {  
  1097.         if (mCardShowType != VerticalA) {  
  1098.             mCardShowType = VerticalA;  
  1099.             m_pForeSprite->setVisible(false);  
  1100.             m_pForeSpriteMirror->setVisible(false);  
  1101.             m_pBgSprite->setVisible(false);  
  1102.             m_pBgSpriteMirror->setVisible(false);  
  1103.   
  1104.             m_pForeSpriteVertical->setVisible(false);  
  1105.             m_pForeSpriteMirrorVertical->setVisible(true);  
  1106.             m_pBgSpriteVertical->setVisible(false);  
  1107.             m_pBgSpriteMirrorVertical->setVisible(true);  
  1108.   
  1109.             m_pForeSpriteVertical->setRotation(-90);  
  1110.             m_pForeSpriteMirrorVertical->setRotation(-90);  
  1111.             m_pBgSpriteVertical->setRotation(-90);  
  1112.             m_pBgSpriteMirrorVertical->setRotation(-90);  
  1113.   
  1114. //          if (pHorizontalItem && pVerticalAItem && pVerticalEItem)  
  1115. //          {  
  1116. //              pHorizontalItem->unselected();  
  1117. //              pVerticalAItem->selected();  
  1118. //              pVerticalEItem->unselected();  
  1119. //          }  
  1120.         }  
  1121.           
  1122.           
  1123.     }  
  1124. }  
  1125.   
  1126. void PageTurn2::OnClickVerticalE(CCObject* pObject)  
  1127. {  
  1128.     NtfPlayDefBtnSnd();  
  1129.     if (!mbIsFliped) {  
  1130.         if (mCardShowType != VerticalE) {  
  1131.             mCardShowType = VerticalE;  
  1132.             m_pForeSprite->setVisible(false);  
  1133.             m_pForeSpriteMirror->setVisible(false);  
  1134.             m_pBgSprite->setVisible(false);  
  1135.             m_pBgSpriteMirror->setVisible(false);  
  1136.   
  1137.             m_pForeSpriteVertical->setVisible(false);  
  1138.             m_pForeSpriteMirrorVertical->setVisible(true);  
  1139.             m_pBgSpriteVertical->setVisible(false);  
  1140.             m_pBgSpriteMirrorVertical->setVisible(true);  
  1141.   
  1142.             m_pForeSpriteVertical->setRotation(90);  
  1143.             m_pForeSpriteMirrorVertical->setRotation(90);  
  1144.             m_pBgSpriteVertical->setRotation(90);  
  1145.             m_pBgSpriteMirrorVertical->setRotation(90);  
  1146.   
  1147. //          if (pHorizontalItem && pVerticalAItem && pVerticalEItem)  
  1148. //          {  
  1149. //              pHorizontalItem->unselected();  
  1150. //              pVerticalAItem->unselected();  
  1151. //              pVerticalEItem->selected();  
  1152. //          }  
  1153.         }  
  1154.           
  1155.   
  1156.     }  
  1157. }  
  1158.   
  1159. void PageTurn2::OnClickFlip(cocos2d::CCObject *pObject)  
  1160. {  
  1161.     NtfPlayDefBtnSnd();  
  1162.     if (!mbIsFliped) {  
  1163.         CCSize winSize = CCDirector::sharedDirector()->getWinSize();  
  1164.           
  1165.         judgeIsFlipCard(winSize.width/2 + 300,mCardShowType,true);  
  1166.         mCurIndex = 3;  
  1167.         for (int i = 0; i < sizeof(pos) / sizeof(SuitPosInfo); i++) {  
  1168.             CCNode* pNode = (CCNode*)getChildByTag(i);  
  1169.             if (pNode) {  
  1170.                 pNode->removeFromParentAndCleanup(true);  
  1171.                 String imgName = GetCardFace(mPickAry[i].mGrp, mPickAry[i].mNum);  
  1172.                 CCSprite* sprite = NtfCreateSprite(imgName.c_str());  
  1173.                 sprite->setPosition(ccp(pos[i].fx, pos[i].fy));  
  1174.                 this->addChild(sprite,1,i);  
  1175.             }  
  1176.         }  
  1177.           
  1178.     }  
  1179.       
  1180. }  
  1181.   
  1182.   
  1183. CCSprite* PageTurn2::createPokerCard(CCrdGrp type, CCrdNum num, bool isShowNum)  
  1184. {  
  1185.     CCSize size = CCSizeMake(778, 521);  
  1186.     //牌类型图标的位置信息  
  1187.     static SuitPosInfo s_spi1[] = {{389,260,-90}};  
  1188.     static SuitPosInfo s_spi2[] = {{165,260,-90},{615,260,90}};  
  1189.     static SuitPosInfo s_spi3[] = {{165,260,-90},{615,260,90},{389,260,-90}};  
  1190.     static SuitPosInfo s_spi4[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90}};  
  1191.     static SuitPosInfo s_spi5[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,260,-90}};  
  1192.     static SuitPosInfo s_spi6[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,400,90},{409,125,90}};  
  1193.     static SuitPosInfo s_spi7[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,400,-90},{409,125,-90},{290,260,-90}};  
  1194.     static SuitPosInfo s_spi8[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,400,90},{409,125,90},{290,260,-90},{503,260,90}};  
  1195.     static SuitPosInfo s_spi9[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{475,400,90},{475,125,90},{308,400,-90},{308,125,-90},{389,260,-90}};  
  1196.     static SuitPosInfo s_spi10[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{475,400,90},{475,125,90},{308,400,-90},{308,125,-90},{250,260,-90},{542,260,90}};  
  1197.     static SuitPosInfo s_spiS[] = {{389,260,-90},{399,260,90},{177,135,-90},{596,385,90}};  
  1198.       
  1199.     //牌数字图标的位置信息  
  1200.     static SuitPosInfo s_spiNumPos[] = {{100,42,-90},{680,480,90}};  
  1201.       
  1202.     std::string imageName;  
  1203.     std::string numImgName;  
  1204.     int nCardNum;  
  1205.     CCSprite* pForeBg = NtfCreateSprite("Cards/card_fore.png");  
  1206.       
  1207.       
  1208.     switch (type) {  
  1209.         case CRDG_SPADE:  
  1210.             imageName = "Cards/spade.png";  
  1211.             numImgName = "Cards/spade_";  
  1212.             break;  
  1213.         case CRDG_HEART:  
  1214.             imageName = "Cards/heart.png";  
  1215.             numImgName = "Cards/heart_";  
  1216.             break;  
  1217.         case CRDG_CLUB:  
  1218.             imageName = "Cards/club.png";  
  1219.             numImgName = "Cards/club_";  
  1220.             break;  
  1221.         case CRDG_DIAMOND:  
  1222.             imageName = "Cards/diamond.png";  
  1223.             numImgName = "Cards/diamond_";  
  1224.             break;  
  1225.               
  1226.         default:  
  1227.             break;  
  1228.     }  
  1229.       
  1230.     String centerImgName;  
  1231.     //添加牌型ICON  
  1232.     switch (num) {  
  1233.         case CRDN_A:  
  1234.             nCardNum = 1;  
  1235.             if (type == CRDG_SPADE) {  
  1236.                 imageName = "Cards/spade_a_center.png";  
  1237.             }  
  1238.             for (int i = 0; i < nCardNum; i++) {  
  1239.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1240.                 pSprite->setPosition(ccp(s_spi1[i].fx,s_spi1[i].fy));  
  1241.                 pSprite->setRotation(s_spi1[i].fRotate);  
  1242.                 pForeBg->addChild(pSprite);  
  1243.                   
  1244.             }  
  1245.               
  1246.             numImgName.append("a.png");  
  1247.             break;  
  1248.         case CRDN_N2:  
  1249.             nCardNum = 2;  
  1250.             for (int i = 0; i < nCardNum; i++) {  
  1251.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1252.                 pSprite->setPosition(ccp(s_spi2[i].fx,s_spi2[i].fy));  
  1253.                 pSprite->setRotation(s_spi2[i].fRotate);  
  1254.                 pForeBg->addChild(pSprite);  
  1255.                   
  1256.             }  
  1257.               
  1258.             numImgName.append("2.png");  
  1259.             break;  
  1260.         case CRDN_N3:  
  1261.             nCardNum = 3;  
  1262.             for (int i = 0; i < nCardNum; i++) {  
  1263.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1264.                 pSprite->setPosition(ccp(s_spi3[i].fx,s_spi3[i].fy));  
  1265.                 pSprite->setRotation(s_spi3[i].fRotate);  
  1266.                 pForeBg->addChild(pSprite);  
  1267.                   
  1268.             }  
  1269.               
  1270.             numImgName.append("3.png");  
  1271.             break;  
  1272.         case CRDN_N4:  
  1273.             nCardNum = 4;  
  1274.             for (int i = 0; i < nCardNum; i++) {  
  1275.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1276.                 pSprite->setPosition(ccp(s_spi4[i].fx,s_spi4[i].fy));  
  1277.                 pSprite->setRotation(s_spi4[i].fRotate);  
  1278.                 pForeBg->addChild(pSprite);  
  1279.                   
  1280.             }  
  1281.               
  1282.             numImgName.append("4.png");  
  1283.             break;  
  1284.         case CRDN_N5:  
  1285.             nCardNum = 5;  
  1286.             for (int i = 0; i < nCardNum; i++) {  
  1287.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1288.                 pSprite->setPosition(ccp(s_spi5[i].fx,s_spi5[i].fy));  
  1289.                 pSprite->setRotation(s_spi5[i].fRotate);  
  1290.                 pForeBg->addChild(pSprite);  
  1291.                   
  1292.             }  
  1293.               
  1294.             numImgName.append("5.png");  
  1295.             break;  
  1296.         case CRDN_N6:  
  1297.             nCardNum = 6;  
  1298.             for (int i = 0; i < nCardNum; i++) {  
  1299.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1300.                 pSprite->setPosition(ccp(s_spi6[i].fx,s_spi6[i].fy));  
  1301.                 pSprite->setRotation(s_spi6[i].fRotate);  
  1302.                 pForeBg->addChild(pSprite);  
  1303.                   
  1304.             }  
  1305.               
  1306.             numImgName.append("6.png");  
  1307.             break;  
  1308.         case CRDN_N7:  
  1309.             nCardNum = 7;  
  1310.             for (int i = 0; i < nCardNum; i++) {  
  1311.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1312.                 pSprite->setPosition(ccp(s_spi7[i].fx,s_spi7[i].fy));  
  1313.                 pSprite->setRotation(s_spi7[i].fRotate);  
  1314.                 pForeBg->addChild(pSprite);  
  1315.                   
  1316.             }  
  1317.               
  1318.             numImgName.append("7.png");  
  1319.             break;  
  1320.         case CRDN_N8:  
  1321.             nCardNum = 8;  
  1322.             for (int i = 0; i < nCardNum; i++) {  
  1323.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1324.                 pSprite->setPosition(ccp(s_spi8[i].fx,s_spi8[i].fy));  
  1325.                 pSprite->setRotation(s_spi8[i].fRotate);  
  1326.                 pForeBg->addChild(pSprite);  
  1327.                   
  1328.             }  
  1329.               
  1330.             numImgName.append("8.png");  
  1331.             break;  
  1332.         case CRDN_N9:  
  1333.             nCardNum = 9;  
  1334.             for (int i = 0; i < nCardNum; i++) {  
  1335.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1336.                 pSprite->setPosition(ccp(s_spi9[i].fx,s_spi9[i].fy));  
  1337.                 pSprite->setRotation(s_spi9[i].fRotate);  
  1338.                 pForeBg->addChild(pSprite);  
  1339.                   
  1340.             }  
  1341.               
  1342.             numImgName.append("9.png");  
  1343.             break;  
  1344.         case CRDN_N10:  
  1345.             nCardNum = 10;  
  1346.             for (int i = 0; i < nCardNum; i++) {  
  1347.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1348.                 pSprite->setPosition(ccp(s_spi10[i].fx,s_spi10[i].fy));  
  1349.                 pSprite->setRotation(s_spi10[i].fRotate);  
  1350.                 pForeBg->addChild(pSprite);  
  1351.                   
  1352.             }  
  1353.               
  1354.             numImgName.append("10.png");  
  1355.             break;  
  1356.         case CRDN_J:  
  1357.             nCardNum = 11;  
  1358.             if (type == CRDG_HEART || type == CRDG_DIAMOND) {  
  1359.                 centerImgName = "Cards/red_j.png";  
  1360.             }  
  1361.             else if(type == CRDG_SPADE || type == CRDG_CLUB)  
  1362.             {  
  1363.                 centerImgName = "Cards/black_j.png";  
  1364.             }  
  1365.             for (int i = 0; i < 1; i++) {  
  1366.                 CCSprite* pSprite = NtfCreateSprite(centerImgName.c_str());  
  1367.                 if (i == 0) {  
  1368.                     pSprite->setAnchorPoint(ccp(0.5, 0.5));  
  1369.                 }  
  1370.                 else  
  1371.                 {  
  1372.                     pSprite->setAnchorPoint(ccp(0.5, 0));  
  1373.                 }  
  1374.                 pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));  
  1375.                 pSprite->setRotation(s_spiS[i].fRotate);  
  1376.                 pForeBg->addChild(pSprite);  
  1377.             }  
  1378.               
  1379.             for (int i = 2; i < 4; i++) {  
  1380.                 CCSprite* pSprite = NtfCreateSprite(imageName.c_str());  
  1381.                 pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));  
  1382.                 pSprite->setRotation(s_spiS[i].fRotate);  
  1383.                 pSprite->setScale(0.8f);  
  1384.                 pForeBg->addChild(pSprite);  
  1385.             }  
  1386.               
  1387.             numImgName.append("j.png");  
  1388.             break;  
  1389.         case CRDN_Q:  
  1390.             nCardNum = 12;  
  1391.             if (type == CRDG_HEART || type == CRDG_DIAMOND) {  
  1392.                 centerImgName = "Cards/red_q.png";  
  1393.             }  
  1394.             else if(type == CRDG_SPADE || type == CRDG_CLUB)  
  1395.             {  
  1396.                 centerImgName = "Cards/black_q.png";  
  1397.             }  
  1398.             for (int i = 0; i < 1; i++) {  
  1399.                 CCSprite* pSprite = NtfCreateSprite(centerImgName.c_str());  
  1400.                 if (i == 0) {  
  1401.                     pSprite->setAnchorPoint(ccp(0.5, 0.5));  
  1402.                 }  
  1403.                 else  
  1404.                 {  
  1405.                     pSprite->setAnchorPoint(ccp(0.5, 0));  
  1406.                 }  
  1407.                 pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));  
  1408.                 pSprite->setRotation(s_spiS[i].fRotate);  
  1409.                 pForeBg->addChild(pSprite);  
  1410.             }  
  1411.             for (int i = 2; i < 4; i++) {  
  1412.                 CCSprite* pSprite = NtfCreateSprite

你可能感兴趣的:(iOS)