2dx翻页容器 cocos_cocos2dx 翻页效果 - CSDN
  • cocos2dx-容器的使用

    2017-09-12 11:55:20
    除了布局容器,我们常用的还有滚动层容器,它可以扩大我们的显示控件,当内容元素很多时,尤为有用。可以设置为两个方向,横向或者是竖向。UIScrollView* scrollView = UIScrollView::create(); scrollView->...
    除了布局容器,我们常用的还有滚动层容器,它可以扩大我们的显示控件,当内容元素很多时,尤为有用。可以设置为两个方向,横向或者是竖向。
    UIScrollView* scrollView = UIScrollView::create();
        scrollView->setTouchEnabled(true);
        scrollView->setSize(Size(280, 150));        
        Size backgroundSize = background->getContentSize();
        scrollView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - scrollView->getSize().width) / 2,
                               (widgetSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - scrollView->getSize().height) / 2));
    
        m_pUiLayer->addWidget(scrollView);
    
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
    
        float innerWidth = scrollView->getSize().width;
        float innerHeight = scrollView->getSize().height + imageView->getSize().height;
    
        scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));    
    
        imageView->setPosition(Point(innerWidth / 2, imageView->getSize().height / 2));
        scrollView->addChild(imageView);
    
        // 为 scrollview 添加其它控件,省略

    请看如图效果,这里创建了一个 ScrollView 控件,并且添加了一些内部元素,以完成布局,控件内容超出显示区域,我们可以通过上下拖动,来显示上下未未显示的不分。

    注意: imageView 设置的位置在 scrollview 之外,可以通过 scrollview 的 setInnerContainerSize 方法设置包含内容的区域大小,在拖动的过程中,边界检查。

    如果是设置横向的拖动效果,我们只需要设置 InnerContainerSize 的 宽度大于控件的大小,高度相同,就能实现横向的拖动效果。

    容器层的使用-UIListView

    UIListView, UIListViewEx(2.2.1)

    ListView 继承自 ScrollView,所以 ScrollView 里面有的功能,特性,在 ListView 中也都能体现出来。那么 ListView 相比较 ScrollView 多了些什么呢?还是先从使用方法上开始:

    UIListView* lv = UIListView::create();
        UIButton* model = UIButton::create();
        model->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        lv->setItemModel(model);
    
        for (int i=0; i<20; i++)
        {
            lv->pushBackDefaultItem();
        }
        lv->setItemsMargin(10);
        lv->setGravity(LISTVIEW_GRAVITY_CENTER_HORIZONTAL);
        lv->setSize(Size(100, 100));
        lv->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        lv->setBackGroundColor(Color3B::GREEN);
        lv->setPosition(Point(100, 100));
        m_pUiLayer->addWidget(lv);


    如图,但不能很好的看到效果,这里是类似 ScrollView 的实现,可以实现拖动,并且有二十个按钮在这其中。先说说普通的属性,通过ItemsMargin 设置每个元素的间距, 通过 Gravity 设置布局方案,这里是横向剧中显示。

    lv->setItemModel(model) 为 ListView 设置了默认的项 (Default Item),然后通过一个 for 循环,添加了 20 次此默认的项,注意这 20 次并不是说, model 被添加了 20 次,二十在每次添加的时候都对 model 做了一个 克隆,它们拥有相同的属性,但却不是同一个对象。

    除了使用 pushBackDefaultItem() 为 ListView 添加项之外,我们还可以通过以下方法添加:


    除了使用 pushBackDefaultItem() 为 ListView 添加项之外,我们还可以通过以下方法添加:

    方法 说明
    pushBackDefaultItem() 添加一个默认项
    insertDefaultItem(int index) 插入一个默认项,有序的
    pushBackCustomItem(UIWidget* item) 添加一个新项
    insertCustomItem(UIWidget* item, int index) 插入一个新项

    以上是提供的一些添加项的方法,除了以上还有一些删除的方法,获取的方法,以便我们能够灵活的操作其中的每个元素:

    removeItem(int index) 移除一个项
    removeLastItem() 移除最后一个项
    getItem(unsigned int index) 根据索引获取一个项
    getItems() 获取所有项,返回 Array 集合
    getIndex(UIWidget *item) 获取一个项的索引

    容器层的使用- UIPageView

    除了可以滚动显示的 ScrollView , 根据项来显示列表的控件之外,还有可以根据 页 来显示 PageView。 PageVew 可以让我们整页整页的显示内容,并且可以做自动对齐,什么是自动对齐,就像你的书翻页,只翻了一半,它回自动帮你翻过去一样。

    UIPageView* pageView = UIPageView::create();
        pageView->setTouchEnabled(true);
        pageView->setSize(Size(240, 130));
        Size backgroundSize = background->getContentSize();
        pageView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
                                  (backgroundSize.width - pageView->getSize().width) / 2,
                                  (widgetSize.height - backgroundSize.height) / 2 +
                                  (backgroundSize.height - pageView->getSize().height) / 2));


        for (int i = 0; i < 3; ++i)
        {
            UILayout* layout = UILayout::create();
            layout->setSize(Size(240, 130));


            UIImageView* imageView = UIImageView::create();
            imageView->setTouchEnabled(true);
            imageView->setScale9Enabled(true);
            imageView->loadTexture("cocosgui/scrollviewbg.png");
            imageView->setSize(Size(240, 130));
            imageView->setPosition(Point(layout->getSize().width / 2, layout->getSize().height / 2));
            layout->addChild(imageView);


            UILabel* label = UILabel::create();
            label->setText(CCString::createWithFormat("page %d", (i + 1))->getCString());
            label->setFontName(font_UIPageViewTest);
            label->setFontSize(30);
            label->setColor(Color3B(192, 192, 192));
            label->setPosition(Point(layout->getSize().width / 2, layout->getSize().height / 2));
            layout->addChild(label);


            pageView->addPage(layout);
        }
        pageView->addEventListenerPageView(this, pagevieweventselector(UIPageViewTest::pageViewEvent));


        m_pUiLayer->addWidget(pageView);



    如图显示,创建了一个 PageView 对象 pageView,设置大小为 "Size(240, 130)",这也就是它的显示区域大小了。我们使用一个 for 循环,添加了三个同样的元素 UILayout ,每个 UILayout 的大小也都是 Size(240, 130),所以 PageView 一次正好能够显示一个项的内容,也就是 "页"。至于每个页的 UILayout 里面装着什么,那就是根据自己的需要而定了。然后使用 pageView->addPage(layout) 添加一个页,需要注意的是,这里所添加的必须是 UILayout 类型对象或者其派生类对象。

    PageView 虽然实现了滑动,滚动的效果,但它并不是继承自 ScrollView 的,而是直接继承自 UILayout 的,那怎么实现滚动的呢,它集成并且实现了 UIScrollInterface 类型,这赋予了它可以滚动的属性。ScrollView 也是同样。

    各个控件组成了丰富的 GUI 界面,而容器层则是其骨架,通过它的布局,来达到我们想要的效果。从 Panel 到 ScrollView ,Listview 和 PageView ,根据实际的需要灵活的组织可以让我们的界面显示的更为友好。




    展开全文
  • cocos2d-x3.10 翻页、翻牌效果的实现 http://blog.csdn.net/glunoy
  • pageView(翻页容器) 使用 开发环境:xcode 、vscode、cocos studio 开发语言:lua 1. ListView (列表容器)使用 local MainScene = class(&amp;quot;MainScene&amp;quot;, cc.load(&amp;quot;...


    开发环境:xcode 、vscode、cocos studio
    开发语言:lua

    1. ListView (列表容器)使用

    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
     
    function MainScene:onCreate()
        -- 测试ListView
        --[[: 1.子节点如果是RichText,或是文本信息。
          设置setVerticalSpace(),高度间隔。adjustToRealHeight(),自适应高度。
            2.设置子节点的锚点信息,否则 高度不对称
        ]]--
     
        self.listView = ccui.ListView:create();  
        self.listView:setPosition(cc.p(10, 10));  
        self.listView:setContentSize(cc.size(1116, 550));  
        self.listView:setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);  
        self.listView:setBounceEnabled(true);  
        self.listView:setItemsMargin(20)  
          
        for i = 1, 4 do  
            local layout = ccui.Layout:create();  
            layout:setContentSize(cc.size(1116, 209));  
            layout:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid);  
            layout:setBackGroundColor(cc.c3b(255, 255, 255));  
      
            self.listView:pushBackCustomItem(layout);  
        end  
        self:addChild(self.listView); 
     
    end
     
    return MainScene
    

    2. scrollView (滚动容器)使用

    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
     
    function MainScene:onCreate()
     
        -- 测试 scrollView
     
        local scrollView = cc.ScrollView:create()
        local layerColor = cc.LayerColor:create(cc.c4b(100, 100,100, 100), 700, 600)
        scrollView:setViewSize(cc.size(700, 300))
        scrollView:setContainer(layerColor)
        layerColor:setPosition(cc.p(0, 0))
        scrollView:setPosition(cc.p(50, 50))
        self:addChild(scrollView)
        scrollView:setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL)--垂直滚动
        scrollView:setBounceEnabled(true)
        scrollView:setDelegate()
        scrollView:registerScriptHandler(handler(self, self.scrollViewDidZoom)  ,cc.SCROLLVIEW_SCRIPT_ZOOM)
        scrollView:registerScriptHandler(handler(self, self.scrollViewDidScroll) ,cc.SCROLLVIEW_SCRIPT_SCROLL)
     
        for i = 1, 6 do
            local strFmt = string.format("num %d", i)
            local label = cc.Label:createWithSystemFont(strFmt, "Arial", 32)
            label:setColor(cc.c3b(255, 0, 0))
            label:setPosition(cc.p(350, 600-i*100+50))
            layerColor:addChild(label)
        end    
     
    end
     
    function MainScene:scrollViewDidZoom()
       print("ScrollViewDidZoom")
    end
     
    function MainScene:scrollViewDidScroll()
       print("ScrollViewDidScroll")
    end
     
     
    return MainScene
    

    tableView 使用

    
    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
     
    function MainScene:onCreate()
     
        -- 测试tableView2
        self.tableView2 = cc.TableView:create(cc.size(200, 200))
        self.tableView2:setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL)
        self.tableView2:setPosition(cc.p(200, 200))
        self.tableView2:setDelegate()
        self:addChild(self.tableView2)
        self.tableView2:registerScriptHandler(handler(self, self.scrollViewDidScroll) , cc.SCROLLVIEW_SCRIPT_SCROLL)
        self.tableView2:registerScriptHandler(handler(self, self.scrollViewDidZoom) , cc.SCROLLVIEW_SCRIPT_ZOOM)
        self.tableView2:registerScriptHandler(handler(self, self.tableCellTouched) , cc.TABLECELL_TOUCHED)
        self.tableView2:registerScriptHandler(handler(self, self.cellSizeForTable) , cc.TABLECELL_SIZE_FOR_INDEX)
        self.tableView2:registerScriptHandler(handler(self, self.tableCellAtIndex) , cc.TABLECELL_SIZE_AT_INDEX)
        self.tableView2:registerScriptHandler(handler(self, self.numberOfCellsInTableView) , cc.NUMBER_OF_CELLS_IN_TABLEVIEW)
        self.tableView2:reloadData()
    end
     
    function MainScene:scrollViewDidScroll(view)
        print("ScrollViewDidScroll")
    end
     
    function MainScene:scrollViewDidZoom(view)
        print("ScrollViewDidZoom")
    end
     
    function MainScene:tableCellTouched(table, cell)
        if nil == cell then
            return
        else
            print("cell touched at index: "..cell:getIdx())
        end
    end
     
    function MainScene:cellSizeForTable(table, idx)
        return 60, 60
    end
     
    function MainScene:tableCellAtIndex(table, idx)
        local strValue = string.format("%d", idx)
        local cell = table:dequeueCell()
        local label = nil
        if nil == cell then
            cell = cc.TableViewCell:create()
            label = cc.Label:createWithSystemFont(strValue, "Arial", 32)
            label:setPosition(cc.p(0, 0))
            label:setAnchorPoint(cc.p(0, 0))
            cell:addChild(label)
            label:setTag(123)
        else
            label = cell:getChildByTag(123)
            if label ~= nil then
                label:setString(strValue)
            end
        end
        return cell
    end
     
    function MainScene:numberOfCellsInTableView(table)
        return 20
    end
     
     
    return MainScene
    

    4. pageView(翻页容器) 使用

    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
     
    function MainScene:onCreate()
     
        -- 测试 pageView
        local pageView = ccui.PageView:create()
        --设置pageView长宽
        pageView:setContentSize(600,600)
        --设置是否响应触摸事件
        pageView:setTouchEnabled(true)
        --设置锚点
        pageView:setAnchorPoint(cc.p(0.5,0.5))
        --设置位置在中心位置
        pageView:setPosition(display.center)
       
        for i=1,5 do
            ---然后layout,每个layout保存一个page
            local layout = ccui.Layout:create()
            --为了演示这里做个小图片
            layout:setContentSize(600,600)
            layout:setPosition(0,0)
            --创建一个button
            local btn= ccui.Button:create("bt_qd.png","bt_qd_h.png","bt_qd.png"):setPosition(300,300)
            layout:addChild(btn)
            pageView:addChild(layout)---一个layout 为一个page内容   page:addPage(layout)
        end
        --添加pageView 到场景中
        self:addChild(pageView)
        
        --添加事件响应
        pageView:addEventListener(handler(self, self.onEvent))
     
    end
     
    --事件响应方法
    function MainScene:onEvent(sender,event)
        if event == ccui.PageViewEventType.turning then
            local pageNum = sender:getCurrentPageIndex()
            print("is turning,this PageNum:"..pageNum)
        end
    end
     
    return MainScene
    

    以上就是cocos2dx中用到的四种容器

    转载地址:https://blog.csdn.net/u012278016/article/details/80255850

    展开全文
  • cocos2d-x 实现翻书效果

    2019-04-02 09:47:14
    因为项目需求,需要使用cocos实现3d翻书的效果,刚开始确实没有什么思路,cocos2d做3d的效果这...后来想到cocos2dx的例子里有个类似的效果,不过那个是个action,后来看了看感觉还可以,只是效果和我的需求有点差异...

    因为项目需求,需要使用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中这种方法行不通,最终放弃了。

    void MyGrid3D::blit()
    {
        glEnable(GL_CULL_FACE);
        CCDirector::sharedDirector()->setDepthTest(true);
        
        CCGrid3D::blit();
        
        glDisable(GL_CULL_FACE);
        CCDirector::sharedDirector()->setDepthTest(false);
    }

    MyGrid3D* MyGrid3D::create(const CCSize& gridSize,const CCSize& textureSize,bool bReverse)
    {
        MyGrid3D *pRet= new MyGrid3D();
        
        if (pRet)
        {
            if (pRet->initWithSize(gridSize,textureSize,bReverse))
            {
                pRet->autorelease();
            }
            else
            {
                delete pRet;
                pRet = NULL;
            }
        }
        
        return pRet;
    }

    看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);

    
    #include "BoluPageTurn2.h"
    #include "BoluButton.h"
    #include "../BoluMsg/BoluMsgPick.h"
    #include "../BoluStage.h"
    #include "../BoluGame/BoluPropNm.h"
    #include "../BoluPlay/BoluMngTable.h"
    #include "RoundProgress.hpp"
    #include "../BoluUserCfg.h"
    
    #define FLIP_CARD_NUM "FLIPCARDNUM"
    
    SuitPosInfo PageTurn2::pos[] = {{60,400,0},{60,263,0},{60,128,0}};
    
    // implementation of PageTurn2
    PageTurn2::PageTurn2(void):
    m_pForeSprite(NULL),
    m_pBgSprite(NULL),
    m_pBgSpriteMirror(NULL),
    m_pForeSpriteMirror(NULL),
    m_pForeSpriteVertical(NULL),
    m_pBgSpriteVertical(NULL),
    m_pBgSpriteMirrorVertical(NULL),
    m_pForeSpriteMirrorVertical(NULL),
    //pHorizontalItem(NULL),
    //pVerticalAItem(NULL),
    //pVerticalEItem(NULL),
    m_pShowPokerCard(NULL),
    mpHideBtn(nullptr),
    mpMenu(nullptr),
    mpAlarmLabel(nullptr),
    mCurLyr(nullptr)
    {
        EventManager::sharedEventManager()->addObserver(this);
    }
    
    PageTurn2::~PageTurn2(void)
    {
        EventManager::sharedEventManager()->removeObserver(this);
    }
    
    bool PageTurn2::init(const PickHAry &ary,int nTableId,int nLeftTime)
    {
        bool bRet = false;
        do
        {
            CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
            CCSize winSize = CCDirector::sharedDirector()->getWinSize();
            setContentSize(winSize);
            int num = GetRayInt(FLIP_CARD_NUM,0);
            if (num < 3) {
                num++;
                SetRayInt(FLIP_CARD_NUM, num);
                NtfShowTipsA("{0xFF0000亲,在设置-系统设置中可关闭或开启搓牌哦}");
            }
            mPickAry = ary;
            mNLeftTM = nLeftTime;
            
            mTableId = nTableId;
            mCurIndex = g_stage->mFlipProgress[mTableId];
            
            CCLayerColor* pBgLayer = CCLayerColor::create(ccc4(0, 0, 0, 125));
            pBgLayer->setContentSize(winSize);
            pBgLayer->setAnchorPoint(ccp(0, 0));
            pBgLayer->setPosition(ccp(0, 0));
            addChild(pBgLayer);
            
            CCSprite* pBgSprite = NtfCreateSprite("FarmAndPine/flip_left_bg.png");
            pBgSprite->setAnchorPoint(ccp(0, 0.5));
            pBgSprite->setPosition(ccp(0, winSize.height/2));
            this->addChild(pBgSprite);
            
            for (int i = 0; i < mPickAry.size(); i++) {
                if (mCurIndex > i)
                {
                    String imgName = GetCardFace(mPickAry[i].mGrp, mPickAry[i].mNum);
                    CCSprite* sprite = NtfCreateSprite(imgName.c_str());
                    sprite->setPosition(ccp(pos[i].fx,pos[i].fy));
                    this->addChild(sprite,1,i);
                }
                else if (mCurIndex == i) {
                    cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/fanpaidonghuazuixin0.png", "BuilderAnimate/fanpaidonghuazuixin0.plist", "BuilderAnimate/fanpaidonghuazuixin.ExportJson");
                    CCArmature* armatureTriangle = cocos2d::extension::CCArmature::create("fanpaidonghuazuixin");
                    armatureTriangle->setAnchorPoint(ccp(0.5, 0.5));
                    armatureTriangle->setPosition(ccp(pos[i].fx, pos[i].fy));
                    armatureTriangle->getAnimation()->playWithIndex(0);
                    this->addChild(armatureTriangle,1,mCurIndex);
                }
                else
                {
                   
                    CCSprite* sprite = NtfCreateSprite("SmallImg/bkg_playboard06.png");
                    sprite->setPosition(ccp(pos[i].fx, pos[i].fy));
                    this->addChild(sprite,1,i);
                    
                }
            }
            m_sGridSize = CCSizeMake(50, 50);
            
            createPokerSprite(ary[mCurIndex].mGrp,ary[mCurIndex].mNum);
            
            
            
            
            
            // 玩家头像
            String sImg = g_pSelf->GetSelfIcon();
            if (sImg.empty())
                sImg = "ImgIcon/bkgIconCircle01.png";
            
            CCClippingNode* clipA = NtfSetHeadIcon(sImg.c_str(), CCSize(56, 56));
            clipA->setAnchorPoint(ccp(0.5, 0.5));
            clipA->setPosition(ccp(60, winSize.height - 118));
            this->addChild(clipA, 30,TAG_AVATAR);
            
            
            //搓牌倒计时
            CCSprite* pTimerBg = NtfCreateSprite("SmallImg/bkg_pic_Other.png");
            pTimerBg->setAnchorPoint(ccp(0.5, 0.5));
            pTimerBg->setPosition(ccp(60, winSize.height - 118));
            addChild(pTimerBg);
            
            g_stage->DisplayAvatar(g_pSelf->GetValue(RVT_ACC_ID), 0);
            
            
            
            std::stringstream s;
            s << mNLeftTM;
            
            CCNode *vNd = AddNumImg(atoi(s.str().c_str()), 10);
            vNd->setPosition(ccp(60, winSize.height - 118));
            vNd->setAnchorPoint(ccp(0.5, 0.5));
            this->addChild(vNd, 60,TAG_TIMER);
    //        mpAlarmLabel = CCLabelTTF::create(s.str().c_str(), "", 22, CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
    //        mpAlarmLabel->setPosition(ccp(60, winSize.height - 118));
    //        mpAlarmLabel->setAnchorPoint(ccp(0.5, 0.5));
    //        this->addChild(mpAlarmLabel,60);
            
            schedule(schedule_selector(PageTurn2::onAlarmUpdate), 1.0f, mNLeftTM, 0.0f);
            
            mFlipDemoOffset = 0;
            schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
            
            RoundProgress* pProgress = RoundProgress::create();
            pProgress->setAnchorPoint(ccp(0.5, 0.5));
            pProgress->setPosition(ccp(pTimerBg->getContentSize().width/2,pTimerBg->getContentSize().height/2));
            pTimerBg->addChild(pProgress, 190);
            pProgress->start(mNLeftTM);
            
            //横置按钮
            SEL_MenuHandler rotate = menu_selector(PageTurn2::OnClickHorizontal);
            CRayButton *pRotateBtn = CRayButton::create("FarmAndPine/btn_rotate_normal.png", "FarmAndPine/btn_rotate_selected.png", NULL);
            pRotateBtn->AttachHandler(this, rotate);
            pRotateBtn->setPosition(ccp(origin.x + winSize.width - pRotateBtn->getContentSize().width / 2 - 100,
                                      origin.y + pRotateBtn->getContentSize().height / 2 + 120));
            pRotateBtn->EnableAnima(false);
            this->addChild(pRotateBtn);
            mTouchLyr.push_back(pRotateBtn);
            
            //开牌按钮
            SEL_MenuHandler flip = menu_selector(PageTurn2::OnClickFlip);
            CRayButton *pFlipBtn = CRayButton::create("FarmAndPine/btn_flipcard_normal.png", "FarmAndPine/btn_flipcard_selected.png", NULL);
            pFlipBtn->AttachHandler(this, flip);
            pFlipBtn->setPosition(ccp(origin.x + winSize.width - pFlipBtn->getContentSize().width / 2 - 100,
                                        origin.y + pFlipBtn->getContentSize().height / 2 + 420));
            pFlipBtn->EnableAnima(false);
            this->addChild(pFlipBtn,5);
            mTouchLyr.push_back(pFlipBtn);
            
            mpHideBtn = CCControlButton::create("", "", 26);
            mpHideBtn->setBackgroundSpriteForState(CCScale9Sprite::create("FarmAndPine/btn_hide_card_normal.png"), CCControlStateNormal);
            mpHideBtn->setBackgroundSpriteForState(CCScale9Sprite::create("FarmAndPine/btn_hide_card_selected.png"), CCControlStateHighlighted);
            mpHideBtn->setAnchorPoint(ccp(0.5, 0.5));
            mpHideBtn->setPosition(ccp(origin.x + winSize.width - mpHideBtn->getContentSize().width/2 - 95,
                                        origin.y + mpHideBtn->getContentSize().height/2 + 370));
            mpHideBtn->setContentSize(CCSizeMake(105, 90));
            mpHideBtn->setPreferredSize(CCSizeMake(105, 90));
            mpHideBtn->setZoomOnTouchDown(false);
            addChild(mpHideBtn,100);
            
            // 按下按钮事件回调
            mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchDownAction), CCControlEventTouchDown);
            // 按钮在其内部拾起事件回调
            mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchUpInsideAction), CCControlEventTouchUpInside);
            //按钮在其外部拾起事件回调
            mpHideBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(PageTurn2::onTouchUpOutsideAction), CCControlEventTouchUpOutside);
            
            if (mCurIndex == mPickAry.size()) {
                mbIsFliped = true;
                mFlipDemoOffset = 0;
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(false);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(false);
                //添加盘牌动画
                m_pShowPokerCard = createPokerCard(mPickAry[mCurIndex-1].mGrp, mPickAry[mCurIndex-1].mNum,true);
                m_pShowPokerCard->setAnchorPoint(ccp(0.5, 0.5));
                m_pShowPokerCard->setPosition(ccp(winSize.width/2, winSize.height/2));
                this->addChild(m_pShowPokerCard,2);
                
                scheduleOnce(schedule_selector(PageTurn2::onRemoveUpdate), 2);
            }
            
            bRet = true;
        }
        while (0);
        return bRet;
    }
    
    void PageTurn2::onRemoveUpdate(float ft)
    {
        g_stage->mFlipProgress[mTableId] = 0;
        removeFromParentAndCleanup(true);
        EventManager::sharedEventManager()->notifyEventFinished(EventShowLastThreeCard);
    
    }
    
    void PageTurn2::onTouchDownAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)
    {
        if (!mbIsFliped) {
            
            if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
                mFlipDemoOffset = 0;
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(false);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(false);
            }
            else
            {
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(false);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(false);
            }
        }
        
        
    }
    
    void PageTurn2::onTouchUpInsideAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)
    {
        if (!mbIsFliped) {
            
            if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
                mFlipDemoOffset = 0;
                schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(true);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(true);
            }
            else
            {
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(true);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(true);
            }
        }
        
    }
    
    void PageTurn2::onTouchUpOutsideAction(cocos2d::CCObject *sender, CCControlEvent controlEvent)
    {
        if (!mbIsFliped) {
            
            if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
                mFlipDemoOffset = 0;
                schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(true);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(true);
            }
            else
            {
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(true);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(true);
            }
        }
        
    }
    
    void PageTurn2::createPokerSprite(CCrdGrp type, CCrdNum num)
    {
        //水平牌
        m_pForeSprite = createPokerCard(type, num,false);
        m_pForeSprite->setAnchorPoint(ccp(0.5, 0.5));
        m_pForeSprite->setPosition(ccp(m_pForeSprite->getContentSize().width/2, m_pForeSprite->getContentSize().height/2));
        m_pForeSprite->setFlipX(true);
        this->addChild(m_pForeSprite,2);
        m_pForeSprite->setVisible(false);
        
        m_pForeSpriteMirror = createPokerCard(type, num,false);
        m_pForeSpriteMirror->setAnchorPoint(ccp(0.5, 0.5));
        m_pForeSpriteMirror->setPosition(ccp(mHOffsetX + m_pForeSpriteMirror->getContentSize().width/2,mHOffsetY + m_pForeSpriteMirror->getContentSize().height/2));
        this->addChild(m_pForeSpriteMirror);
        
        m_pBgSprite = NtfCreateSprite("Cards/card_bg.png");
        m_pBgSprite->setAnchorPoint(ccp(0.5, 0.5));
        m_pBgSprite->setPosition(ccp(m_pBgSprite->getContentSize().width/2, m_pBgSprite->getContentSize().height/2));
        this->addChild(m_pBgSprite,1);
        m_pBgSprite->setVisible(false);
        
        m_pBgSpriteMirror = NtfCreateSprite("Cards/card_bg.png");
        m_pBgSpriteMirror->setAnchorPoint(ccp(0.5, 0.5));
        m_pBgSpriteMirror->setPosition(ccp(mHOffsetX + m_pBgSpriteMirror->getContentSize().width/2,mHOffsetY + m_pBgSpriteMirror->getContentSize().height/2));
        this->addChild(m_pBgSpriteMirror);
        
        //竖直牌
        m_pForeSpriteVertical = createPokerCard(type, num,false);
        m_pForeSpriteVertical->setAnchorPoint(ccp(0.5, 0.5));
        m_pForeSpriteVertical->setPosition(ccp(m_pForeSpriteVertical->getContentSize().height/2 ,m_pForeSpriteVertical->getContentSize().width/2));
        m_pForeSpriteVertical->setFlipX(true);
        this->addChild(m_pForeSpriteVertical,2);
        m_pForeSpriteVertical->setVisible(false);
        m_pForeSpriteVertical->setRotation(90);
        
        m_pForeSpriteMirrorVertical = createPokerCard(type, num,false);
        m_pForeSpriteMirrorVertical->setAnchorPoint(ccp(0.5, 0.5));
        m_pForeSpriteMirrorVertical->setPosition(ccp(mVOffsetX + m_pForeSpriteMirrorVertical->getContentSize().height/2 ,mVOffsetY + m_pForeSpriteMirrorVertical->getContentSize().width/2));
        this->addChild(m_pForeSpriteMirrorVertical);
        m_pForeSpriteMirrorVertical->setRotation(90);
        
        
        m_pBgSpriteVertical = NtfCreateSprite("Cards/card_bg.png");
        m_pBgSpriteVertical->setAnchorPoint(ccp(0.5, 0.5));
        m_pBgSpriteVertical->setPosition(ccp(m_pBgSpriteVertical->getContentSize().height/2 ,m_pBgSpriteVertical->getContentSize().width/2));
        this->addChild(m_pBgSpriteVertical,1);
        m_pBgSpriteVertical->setVisible(false);
        m_pBgSpriteVertical->setRotation(90);
        
        m_pBgSpriteMirrorVertical = NtfCreateSprite("Cards/card_bg.png");
        m_pBgSpriteMirrorVertical->setAnchorPoint(ccp(0.5, 0.5));
        m_pBgSpriteMirrorVertical->setPosition(ccp(mVOffsetX + m_pBgSpriteMirrorVertical->getContentSize().height/2 ,mVOffsetY + m_pBgSpriteMirrorVertical->getContentSize().width/2));
        this->addChild(m_pBgSpriteMirrorVertical);
        m_pBgSpriteMirrorVertical->setRotation(90);
        
        
        if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
            m_pForeSpriteVertical->setVisible(false);
            m_pForeSpriteMirrorVertical->setVisible(false);
            m_pBgSpriteVertical->setVisible(false);
            m_pBgSpriteMirrorVertical->setVisible(false);
        }
        
    //    cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/cuowo-triangle0.png", "BuilderAnimate/cuowo-triangle0.plist", "BuilderAnimate/cuowo-triangle.ExportJson");
    //    CCArmature* armatureTriangle = cocos2d::extension::CCArmature::create("cuowo-triangle");
    //    armatureTriangle->setAnchorPoint(ccp(1, 0));
    //    armatureTriangle->setPosition(ccp(m_pBgSprite->getContentSize().width, 0));
    //    armatureTriangle->getAnimation()->playWithIndex(0);
    //    m_pBgSpriteMirror->addChild(armatureTriangle);
    //    
    //    
    //    cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/cuopai0.png", "BuilderAnimate/cuopai0.plist", "BuilderAnimate/cuopai.ExportJson");
    //    CCArmature* armature = cocos2d::extension::CCArmature::create("cuopai");
    //    armature->setAnchorPoint(ccp(0, 0));
    //    armature->setPosition(ccp(m_pBgSprite->getContentSize().width, 0));
    //    armature->setRotation(-90);
    //    armature->getAnimation()->playWithIndex(0);
    //    m_pBgSpriteMirrorVertical->addChild(armature);
    //    
    //    CCArmature* armature2 = cocos2d::extension::CCArmature::create("cuopai");
    //    armature2->setAnchorPoint(ccp(0, 0));
    //    armature2->setPosition(ccp(0, m_pBgSprite->getContentSize().height));
    //    armature2->setRotation(90);
    //    armature2->getAnimation()->playWithIndex(0);
    //    m_pBgSpriteMirrorVertical->addChild(armature2);
        
        startWithTarget(m_pForeSprite,true,m_pForeSprite->getContentSize());
        startWithTarget(m_pBgSprite,false,m_pBgSprite->getContentSize());
        
        startWithTarget(m_pForeSpriteVertical, true, CCSizeMake(m_pForeSpriteVertical->getContentSize().height, m_pForeSpriteVertical->getContentSize().width));
        startWithTarget(m_pBgSpriteVertical, false, CCSizeMake(m_pBgSpriteVertical->getContentSize().height, m_pBgSpriteVertical->getContentSize().width));
    }
    
    
    void PageTurn2::onAlarmUpdate(float ft)
    {
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        CCNode* pNode = getChildByTag(TAG_TIMER);
        if (pNode) {
            pNode->removeFromParent();
            
            mNLeftTM--;
            if (mNLeftTM <= 0) {
                OnClickFlip(nullptr);
                unschedule(schedule_selector(PageTurn2::onAlarmUpdate));
            }
            std::stringstream s;
            s << mNLeftTM;
            CCNode *vNd = AddNumImg(atoi(s.str().c_str()), 10);
            vNd->setPosition(ccp(60, winSize.height - 118));
            vNd->setAnchorPoint(ccp(0.5, 0.5));
            this->addChild(vNd, 60,TAG_TIMER);
            
        }
    //    if (mpAlarmLabel) {
    //        mNLeftTM--;
    //        if (mNLeftTM <= 0) {
    //            OnClickFlip(nullptr);
    //            unschedule(schedule_selector(PageTurn2::onAlarmUpdate));
    //        }
    //        std::stringstream s;
    //        s << mNLeftTM;
    //        
    //        
    //        mpAlarmLabel->setString(s.str().c_str());
    //    }
    }
    
    void PageTurn2::onFlipDemoUpdate(float ft)
    {
        if (mFlipDemoOffset > 100) {
            isIncrease = false;
        }
        else if(mFlipDemoOffset <= 0)
        {
            isIncrease = true;
        }
        if (isIncrease)
        {
            mFlipDemoOffset += 2;
        }
        else
        {
            mFlipDemoOffset -= 2;;
        }
        
        if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
            if (!m_pBgSprite->isVisible()) {
                m_pBgSprite->setVisible(true);
                m_pBgSpriteMirror->setVisible(false);
            }
            if (!m_pForeSprite->isVisible()) {
                m_pForeSprite->setVisible(true);
                m_pForeSpriteMirror->setVisible(false);
            }
        }
        else
        {
            if (!m_pBgSpriteVertical->isVisible()) {
                m_pBgSpriteVertical->setVisible(true);
                m_pBgSpriteMirrorVertical->setVisible(false);
            }
            if (!m_pForeSpriteVertical->isVisible()) {
                m_pForeSpriteVertical->setVisible(true);
                m_pForeSpriteMirrorVertical->setVisible(false);
            }
        }
        
        
        calculateHorizontalVertexPoints(mFlipDemoOffset / cosf(M_PI / 4),true);
    }
    
    PageTurn2* PageTurn2::create(const PickHAry &ary,int nTableId,int nLeftTime)
    {
        PageTurn2 * pRet = new PageTurn2();
        if (pRet && pRet->init(ary,nTableId,nLeftTime))
        {
            pRet->autorelease();
        }
        else
        {
            CC_SAFE_DELETE(pRet);
        }
        return pRet;
    }
    
    
    
    
    MyGrid3D* PageTurn2::getGrid(bool bReverse,const CCSize& size)
    {
        return MyGrid3D::create(m_sGridSize,size,bReverse);
    }
    
    void PageTurn2::startWithTarget(CCNode *pTarget, bool bReverse, const CCSize& size)
    {
        
        CCGridBase *newgrid = this->getGrid(bReverse,size);
        
        CCNode *t = pTarget;
        CCGridBase *targetGrid = t->getGrid();
        
        if (targetGrid && targetGrid->getReuseGrid() > 0)
        {
            if (targetGrid->isActive() && targetGrid->getGridSize().width == m_sGridSize.width
                && targetGrid->getGridSize().height == m_sGridSize.height /*&& dynamic_cast<CCGridBase*>(targetGrid) != NULL*/)
            {
                targetGrid->reuse();
            }
            else
            {
                CCAssert(0, "");
            }
        }
        else
        {
            if (targetGrid && targetGrid->isActive())
            {
                targetGrid->setActive(false);
            }
            
            t->setGrid(newgrid);
            t->getGrid()->setActive(true);
        }
    }
    
    ccVertex3F PageTurn2::vertex(const CCPoint& position,CCNode *pTarget)
    {
        CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();
        return g->vertex(position);
    }
    
    ccVertex3F PageTurn2::originalVertex(const CCPoint& position,CCNode *pTarget)
    {
        CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();
        return g->originalVertex(position);
    }
    
    void PageTurn2::setVertex(const CCPoint& position, const ccVertex3F& vertex,CCNode *pTarget)
    {
        CCGrid3D *g = (CCGrid3D*)pTarget->getGrid();
        g->setVertex(position, vertex);
    }
    
    void PageTurn2::registerWithTouchDispatcher()
    {
    //    CCDirector* pDirec = CCDirector::sharedDirector();
    //    pDirec->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
    }
    
    bool PageTurn2::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
        CCPoint point = pTouch->getLocation();
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        
        float borderXH = winSize.width/2 + m_pBgSprite->getContentSize().width/2;
        float borderYH = winSize.height/2 - m_pBgSprite->getContentSize().height/2;
        float borderXHMin = winSize.width/2 - m_pBgSprite->getContentSize().width/2;
        
        float borderXVMax = winSize.width/2 + m_pBgSprite->getContentSize().height/2;
        float borderXVMin = winSize.width/2 - m_pBgSprite->getContentSize().height/2;
        float borderYV = mVOffsetY;
        
        if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
            if (point.x > borderXH - 150 && point.x < borderXH && point.y > borderYH && point.y < borderYH + 150)
            {
                //触摸牌的右下角
                mTouchBegin = pTouch->getLocation();
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
            }
            else if (point.x > borderXHMin && point.x < borderXHMin + 150 && point.y > borderYH && point.y < borderYH + 150)
            {//触摸牌的左下角
                mTouchBegin = pTouch->getLocation();
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
            }
            else
            {
                mTouchBegin = CCPoint(0, 0);
            }
        }
        else
        {
            if (point.x > borderXVMin && point.x < borderXVMax && point.y > borderYV && point.y < borderYV + 150)
            {
                //垂直情况下触摸牌的下边缘
                mTouchBegin = pTouch->getLocation();
            }
            else
            {
                mTouchBegin = CCPoint(0, 0);
            }
        }
        
        
        return false;
    }
    
    void PageTurn2::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
        if (mTouchBegin.x != 0 && mTouchBegin.y != 0 && !mbIsFliped) {
            if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
                if (!m_pBgSprite->isVisible()) {
                    m_pBgSprite->setVisible(true);
                    m_pBgSpriteMirror->setVisible(false);
                }
                if (!m_pForeSprite->isVisible()) {
                    m_pForeSprite->setVisible(true);
                    m_pForeSpriteMirror->setVisible(false);
                }
            }
            else
            {
                if (!m_pBgSpriteVertical->isVisible()) {
                    m_pBgSpriteVertical->setVisible(true);
                    m_pBgSpriteMirrorVertical->setVisible(false);
                }
                if (!m_pForeSpriteVertical->isVisible()) {
                    m_pForeSpriteVertical->setVisible(true);
                    m_pForeSpriteMirrorVertical->setVisible(false);
                }
            }
            
            
            float offsetX = mTouchBegin.x - pTouch->getLocation().x;
            float offsetY = pTouch->getLocation().y - mTouchBegin.y;
            bool flag;
            if (offsetX > 0) {
                flag = true;
            }
            else
            {
                flag = false;
            }
            
            float offset = fabs(offsetX) > offsetY ? offsetX : offsetY;
            calculateHorizontalVertexPoints(offset / cosf(M_PI/4), flag);
            
            calculateVerticalVertexPoints(offsetY);
            
            if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
    //            CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, offsetX);
                judgeIsFlipCard(fabsf(offsetX) / cosf(M_PI / 4),mCardShowType,true);
            }
            else if (mCardShowType == VerticalA || mCardShowType == VerticalE)
            {
    //            CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, offsetY);
                judgeIsFlipCard(offsetY / cosf(M_PI / 4),mCardShowType,true);
            }
        }
    }
    
    void PageTurn2::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
       if (mTouchBegin.x != 0 && mTouchBegin.y != 0 && !mbIsFliped) {
           
           calculateHorizontalVertexPoints(0,true);
           calculateVerticalVertexPoints(-mVOffsetY);
           if (mCardShowType == Horizontal || mCardShowType == Horizontal2) {
    //           CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, 0);
           }
           else if (mCardShowType == VerticalA || mCardShowType == VerticalE)
           {
    //           CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum, mCardShowType, -mVOffsetY);
           }
       }
    }
    
    void PageTurn2::calculateHorizontalVertexPoints(float offsetX,bool flag)
    {
        
        float R = 50;
        
        if (flag)
        {
            float theta = (GLfloat)(M_PI / 6.0f);
            float b = (m_pBgSprite->getContentSize().width - offsetX * 1.4f) * sinf(theta);
            
            for (int i = 0; i <= m_sGridSize.width; ++i)
            {
                for (int j = 0; j <= m_sGridSize.height; ++j)
                {
                    // Get original vertex
                    ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSprite);
                    
                    float x = (p.y + b) / tanf(theta);
                    
                    float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);
                    float pivotY = pivotX * tanf(theta) - b;
                    
                    float l = (p.x - pivotX) / sinf(theta);
                    float alpha = l / R;
                    if (l >= 0) {
                        if (alpha > M_PI) {
                            p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha - M_PI) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));
                            p.z = (GLfloat)(2 * R / 9);
                        }
                        else if (alpha <= M_PI)
                        {
                            p.x = (GLfloat)(mHOffsetX + pivotX + R * sinf(alpha) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));
                            p.z = (GLfloat)((R - R * cosf(alpha)) / 9);
                        }
                    }
                    else
                    {
                        p.x += mHOffsetX;
                        p.y += mHOffsetY;
                    }
                    
                    // Set new coords
                    setVertex(ccp(i, j), p,m_pForeSprite);
                    
                    
                }
            }
            
            for (int i = 0; i <= m_sGridSize.width; ++i)
            {
                for (int j = 0; j <= m_sGridSize.height; ++j)
                {
                    // Get original vertex
                    ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSprite);
                    float x = (p.y + b) / tanf(theta);
                    
                    float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);
                    float pivotY = pivotX * tanf(theta) - b;
                    
                    float l = (p.x - pivotX) / sinf(theta);
                    float alpha = l / R;
                    if (l >= 0) {
                        if (alpha > M_PI) {
                            p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha - M_PI) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));
                            p.z = (GLfloat)(2 * R / 9);
                        }
                        else if (alpha <= M_PI)
                        {
                            p.x = (GLfloat)(mHOffsetX + pivotX + R * sinf(alpha) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));
                            p.z = (GLfloat)((R - R * cosf(alpha)) / 9);
                        }
                    }
                    else
                    {
                        p.x += mHOffsetX;
                        p.y += mHOffsetY;
                    }
                    
                    setVertex(ccp(i, j), p,m_pBgSprite);
                    
                    
                    
                }
            }
            
        }
        else
        {
            float theta = (GLfloat)(M_PI / 6.0f);
            float b = fabsf(offsetX * 0.8f);
            for (int i = 0; i <= m_sGridSize.width; ++i)
            {
                for (int j = 0; j <= m_sGridSize.height; ++j)
                {
                    // Get original vertex
                    ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSprite);
                    
                    float x = (p.y - b) / -tanf(theta);
                    
                    float pivotX = p.x + (x - p.x) * sinf(theta) * sinf(theta);
                    float pivotY = pivotX * -tanf(theta) + b;
                    
                    float l = (pivotX - p.x) / sinf(theta);
                    float alpha = l / R;
                    if (l >= 0) {
                        if (alpha > M_PI) {
                            p.x = (GLfloat)(mHOffsetX + pivotX + R * (alpha - M_PI) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));
                            p.z = (GLfloat)(2 * R / 9);
                        }
                        else if (alpha <= M_PI)
                        {
                            p.x = (GLfloat)(mHOffsetX + pivotX - R * sinf(alpha) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));
                            p.z = (GLfloat)((R - R * cosf(alpha)) / 9);
                        }
                    }
                    else
                    {
                        p.x += mHOffsetX;
                        p.y += mHOffsetY;
                    }
                    
                    // Set new coords
                    setVertex(ccp(i, j), p,m_pForeSprite);
                    
                    
                }
            }
            
            for (int i = 0; i <= m_sGridSize.width; ++i)
            {
                for (int j = 0; j <= m_sGridSize.height; ++j)
                {
                    // Get original vertex
                    ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSprite);
                    
                    float x = (p.y - b) / -tanf(theta);
                    
                    float pivotX = p.x + (x - p.x) * sinf(theta) * sinf(theta);
                    float pivotY = pivotX * -tanf(theta) + b;
                    
                    float l = (pivotX - p.x) / sinf(theta);
                    float alpha = l / R;
                    if (l >= 0) {
                        if (alpha > M_PI) {
                            p.x = (GLfloat)(mHOffsetX + pivotX + R * (alpha - M_PI) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha - M_PI) * cosf(theta));
                            p.z = (GLfloat)(2 * R / 9);
                        }
                        else if (alpha <= M_PI)
                        {
                            p.x = (GLfloat)(mHOffsetX + pivotX - R * sinf(alpha) * sinf(theta));
                            p.y = (GLfloat)(mHOffsetY + pivotY - R * sinf(alpha) * cosf(theta));
                            p.z = (GLfloat)((R - R * cosf(alpha)) / 9);
                        }
                    }
                    else
                    {
                        p.x += mHOffsetX;
                        p.y += mHOffsetY;
                    }
    
                    
                    setVertex(ccp(i, j), p,m_pBgSprite);
                }
            }
        }
        
        
        //    float R2 = 50;
        //    float offsetX2 = mTouchBegin.x - pTouch->getLocation().x;
        //    float pivotX2 = m_pForeSpriteVertical->getContentSize().height - offsetX2;
        //
        //
        //    for (int i = 0; i <= m_sGridSize.width; ++i)
        //    {
        //        for (int j = 0; j <= m_sGridSize.height; ++j)
        //        {
        //            // Get original vertex
        //            ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSpriteVertical);
        //            float l = p.x - pivotX2;
        //            float alpha = l / R2;
        //            if (l >= 0) {
        //                if (alpha > M_PI) {
        //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);
        //                    p.z = 2 * R2 / 9;
        //                    p.y = p.y + mVOffsetY;
        //                }
        //                else if (alpha <= M_PI)
        //                {
        //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);
        //                    p.z = (R2 - R2 * cosf(alpha))/9;
        //                    p.y = p.y + mVOffsetY;
        //                }
        //            }
        //            else
        //            {
        //                p.x = p.x + mVOffsetX;
        //                p.y = p.y + mVOffsetY;
        //            }
        //
        //
        //            // Set new coords
        //            setVertex(ccp(i, j), p,m_pForeSpriteVertical);
        //
        //
        //        }
        //    }
        //
        //    for (int i = 0; i <= m_sGridSize.width; ++i)
        //    {
        //        for (int j = 0; j <= m_sGridSize.height; ++j)
        //        {
        //            // Get original vertex
        //            ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSpriteVertical);
        //            float l = p.x - pivotX2;
        //            float alpha = l / R2;
        //            if (l >= 0) {
        //                if (alpha > M_PI) {
        //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);
        //                    p.z = 2 * R2 / 9;
        //                    p.y = p.y + mVOffsetY;
        //                }
        //                else if (alpha <= M_PI)
        //                {
        //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);
        //                    p.z = (R2 - R2 * cosf(alpha))/9;
        //                    p.y = p.y + mVOffsetY;
        //                }
        //            }
        //            else
        //            {
        //                p.x = p.x + mVOffsetX;
        //                p.y = p.y + mVOffsetY;
        //            }
        //
        //            // Set new coords
        //            setVertex(ccp(i, j), p,m_pBgSpriteVertical);
        //            
        //            
        //            
        //        }
        //    }
    }
    
    void PageTurn2::calculateVerticalVertexPoints(float offsetY)
    {
        float R2 = 50;
        float pivotY = offsetY + mVOffsetY;
        
        
        for (int i = 0; i <= m_sGridSize.width; ++i)
        {
            for (int j = 0; j <= m_sGridSize.height; ++j)
            {
                // Get original vertex
                ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSpriteVertical);
                float l = pivotY - p.y;
                float alpha = l / R2;
                if (l >= 0) {
                    if (alpha > M_PI) {
                        p.z = (GLfloat)(2 * R2 / 9);
                        p.y = (GLfloat)(mVOffsetY + pivotY + R2 * (alpha - M_PI));
                        p.x += mVOffsetX;
                    }
                    else if (alpha <= M_PI)
                    {
                        p.z = (GLfloat)((R2 - R2 * cosf(alpha))/9);
                        p.y = (GLfloat)(mVOffsetY + pivotY - R2 * sinf(alpha));
                        
                        p.x += mVOffsetX;
                    }
                }
                else
                {
                    p.x += mVOffsetX;
                    p.y += mVOffsetY;
                }
                
                
                // Set new coords
                setVertex(ccp(i, j), p,m_pForeSpriteVertical);
                
                
            }
        }
        
        for (int i = 0; i <= m_sGridSize.width; ++i)
        {
            for (int j = 0; j <= m_sGridSize.height; ++j)
            {
                // Get original vertex
                ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSpriteVertical);
                float l = pivotY - p.y;
                float alpha = l / R2;
                if (l >= 0) {
                    if (alpha > M_PI) {
                        p.z = (GLfloat)(2 * R2 / 9);
                        p.y = (GLfloat)(mVOffsetY + pivotY + R2 * (alpha - M_PI));
                        p.x += mVOffsetX;
                    }
                    else if (alpha <= M_PI)
                    {
                        p.z = (GLfloat)((R2 - R2 * cosf(alpha))/9);
                        p.y = (GLfloat)(mVOffsetY + pivotY - R2 * sinf(alpha));
                        
                        p.x += mVOffsetX;
                    }
                }
                else
                {
                    p.x += mVOffsetX;
                    p.y += mVOffsetY;
                }            // Set new coords
                setVertex(ccp(i, j), p,m_pBgSpriteVertical);
                
                
                
            }
        }
    }
    
    void PageTurn2::ccTouchCancelled(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
        
    }
    
    void PageTurn2::OnEnterEvn(CCNode*)				// 进入动画结束执行的事件
    {
        
    }
    void PageTurn2::OnExitEvn(CCNode*)					// 退出动画结束执行的事件
    {
        removeFromParent();
    }
    
    // 返回
    void PageTurn2::OnClickBack(CCObject* pObject)
    {
        NtfPlayClose();//关闭的音效
        removeFromParent();
    }
    
    void PageTurn2::OnClickHorizontal(cocos2d::CCObject *pObject)
    {
        NtfPlayDefBtnSnd();
        if (!mbIsFliped) {
            
    		if (mCardShowType != Horizontal && mCardShowType == VerticalE) {
                mFlipDemoOffset = 0;
                schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
    			mCardShowType = Horizontal;
    			m_pForeSprite->setVisible(false);
    			m_pForeSpriteMirror->setVisible(true);
    			m_pBgSprite->setVisible(false);
    			m_pBgSpriteMirror->setVisible(true);
    
    			m_pForeSpriteVertical->setVisible(false);
    			m_pForeSpriteMirrorVertical->setVisible(false);
    			m_pBgSpriteVertical->setVisible(false);
    			m_pBgSpriteMirrorVertical->setVisible(false);
                
                m_pForeSprite->setRotation(0);
                m_pForeSpriteMirror->setRotation(0);
                m_pBgSprite->setRotation(0);
                m_pBgSpriteMirror->setRotation(0);
    
    		}
            else if (mCardShowType == Horizontal)
            {
                mFlipDemoOffset = 0;
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                mCardShowType = VerticalA;
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(false);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(false);
                
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(true);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(true);
                
                m_pForeSpriteVertical->setRotation(-90);
                m_pForeSpriteMirrorVertical->setRotation(-90);
                m_pBgSpriteVertical->setRotation(-90);
                m_pBgSpriteMirrorVertical->setRotation(-90);
            }
            else if (mCardShowType == VerticalA)
            {
                mFlipDemoOffset = 0;
                schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                mCardShowType = Horizontal2;
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(true);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(true);
                
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(false);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(false);
                
                m_pForeSprite->setRotation(180);
                m_pForeSpriteMirror->setRotation(180);
                m_pBgSprite->setRotation(180);
                m_pBgSpriteMirror->setRotation(180);
                
            }
            else if(mCardShowType == Horizontal2)
            {
                mFlipDemoOffset = 0;
                unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
                mCardShowType = VerticalE;
                m_pForeSprite->setVisible(false);
                m_pForeSpriteMirror->setVisible(false);
                m_pBgSprite->setVisible(false);
                m_pBgSpriteMirror->setVisible(false);
                
                m_pForeSpriteVertical->setVisible(false);
                m_pForeSpriteMirrorVertical->setVisible(true);
                m_pBgSpriteVertical->setVisible(false);
                m_pBgSpriteMirrorVertical->setVisible(true);
                
                m_pForeSpriteVertical->setRotation(90);
                m_pForeSpriteMirrorVertical->setRotation(90);
                m_pBgSpriteVertical->setRotation(90);
                m_pBgSpriteMirrorVertical->setRotation(90);
            }
        }
        
    }
    
    void PageTurn2::OnClickVerticalA(CCObject* pObject)
    {
    	NtfPlayDefBtnSnd();
    	if (!mbIsFliped) {
    		if (mCardShowType != VerticalA) {
    			mCardShowType = VerticalA;
    			m_pForeSprite->setVisible(false);
    			m_pForeSpriteMirror->setVisible(false);
    			m_pBgSprite->setVisible(false);
    			m_pBgSpriteMirror->setVisible(false);
    
    			m_pForeSpriteVertical->setVisible(false);
    			m_pForeSpriteMirrorVertical->setVisible(true);
    			m_pBgSpriteVertical->setVisible(false);
    			m_pBgSpriteMirrorVertical->setVisible(true);
    
    			m_pForeSpriteVertical->setRotation(-90);
    			m_pForeSpriteMirrorVertical->setRotation(-90);
    			m_pBgSpriteVertical->setRotation(-90);
    			m_pBgSpriteMirrorVertical->setRotation(-90);
    
    //			if (pHorizontalItem && pVerticalAItem && pVerticalEItem)
    //			{
    //				pHorizontalItem->unselected();
    //				pVerticalAItem->selected();
    //				pVerticalEItem->unselected();
    //			}
    		}
    		
    		
    	}
    }
    
    void PageTurn2::OnClickVerticalE(CCObject* pObject)
    {
    	NtfPlayDefBtnSnd();
    	if (!mbIsFliped) {
    		if (mCardShowType != VerticalE) {
    			mCardShowType = VerticalE;
    			m_pForeSprite->setVisible(false);
    			m_pForeSpriteMirror->setVisible(false);
    			m_pBgSprite->setVisible(false);
    			m_pBgSpriteMirror->setVisible(false);
    
    			m_pForeSpriteVertical->setVisible(false);
    			m_pForeSpriteMirrorVertical->setVisible(true);
    			m_pBgSpriteVertical->setVisible(false);
    			m_pBgSpriteMirrorVertical->setVisible(true);
    
    			m_pForeSpriteVertical->setRotation(90);
    			m_pForeSpriteMirrorVertical->setRotation(90);
    			m_pBgSpriteVertical->setRotation(90);
    			m_pBgSpriteMirrorVertical->setRotation(90);
    
    //			if (pHorizontalItem && pVerticalAItem && pVerticalEItem)
    //			{
    //				pHorizontalItem->unselected();
    //				pVerticalAItem->unselected();
    //				pVerticalEItem->selected();
    //			}
    		}
    		
    
    	}
    }
    
    void PageTurn2::OnClickFlip(cocos2d::CCObject *pObject)
    {
        NtfPlayDefBtnSnd();
        if (!mbIsFliped) {
            CCSize winSize = CCDirector::sharedDirector()->getWinSize();
            
            judgeIsFlipCard(winSize.width/2 + 300,mCardShowType,true);
            mCurIndex = 3;
            for (int i = 0; i < sizeof(pos) / sizeof(SuitPosInfo); i++) {
                CCNode* pNode = (CCNode*)getChildByTag(i);
                if (pNode) {
                    pNode->removeFromParentAndCleanup(true);
                    String imgName = GetCardFace(mPickAry[i].mGrp, mPickAry[i].mNum);
                    CCSprite* sprite = NtfCreateSprite(imgName.c_str());
                    sprite->setPosition(ccp(pos[i].fx, pos[i].fy));
                    this->addChild(sprite,1,i);
                }
            }
            
        }
        
    }
    
    
    CCSprite* PageTurn2::createPokerCard(CCrdGrp type, CCrdNum num, bool isShowNum)
    {
        CCSize size = CCSizeMake(778, 521);
        //牌类型图标的位置信息
        static SuitPosInfo s_spi1[] = {{389,260,-90}};
        static SuitPosInfo s_spi2[] = {{165,260,-90},{615,260,90}};
        static SuitPosInfo s_spi3[] = {{165,260,-90},{615,260,90},{389,260,-90}};
        static SuitPosInfo s_spi4[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90}};
        static SuitPosInfo s_spi5[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,260,-90}};
        static SuitPosInfo s_spi6[] = {{165,400,-90},{165,125,-90},{620,400,90},{620,125,90},{389,400,90},{409,125,90}};
        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}};
        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}};
        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}};
        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}};
        static SuitPosInfo s_spiS[] = {{389,260,-90},{399,260,90},{177,135,-90},{596,385,90}};
        
        //牌数字图标的位置信息
        static SuitPosInfo s_spiNumPos[] = {{100,42,-90},{680,480,90}};
        
        std::string imageName;
        std::string numImgName;
        int nCardNum;
        CCSprite* pForeBg = NtfCreateSprite("Cards/card_fore.png");
        
        
        switch (type) {
            case CRDG_SPADE:
                imageName = "Cards/spade.png";
                numImgName = "Cards/spade_";
                break;
            case CRDG_HEART:
                imageName = "Cards/heart.png";
                numImgName = "Cards/heart_";
                break;
            case CRDG_CLUB:
                imageName = "Cards/club.png";
                numImgName = "Cards/club_";
                break;
            case CRDG_DIAMOND:
                imageName = "Cards/diamond.png";
                numImgName = "Cards/diamond_";
                break;
                
            default:
                break;
        }
        
        String centerImgName;
        //添加牌型ICON
        switch (num) {
            case CRDN_A:
                nCardNum = 1;
                if (type == CRDG_SPADE) {
                    imageName = "Cards/spade_a_center.png";
                }
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi1[i].fx,s_spi1[i].fy));
                    pSprite->setRotation(s_spi1[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("a.png");
                break;
            case CRDN_N2:
                nCardNum = 2;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi2[i].fx,s_spi2[i].fy));
                    pSprite->setRotation(s_spi2[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("2.png");
                break;
            case CRDN_N3:
                nCardNum = 3;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi3[i].fx,s_spi3[i].fy));
                    pSprite->setRotation(s_spi3[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("3.png");
                break;
            case CRDN_N4:
                nCardNum = 4;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi4[i].fx,s_spi4[i].fy));
                    pSprite->setRotation(s_spi4[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("4.png");
                break;
            case CRDN_N5:
                nCardNum = 5;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi5[i].fx,s_spi5[i].fy));
                    pSprite->setRotation(s_spi5[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("5.png");
                break;
            case CRDN_N6:
                nCardNum = 6;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi6[i].fx,s_spi6[i].fy));
                    pSprite->setRotation(s_spi6[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("6.png");
                break;
            case CRDN_N7:
                nCardNum = 7;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi7[i].fx,s_spi7[i].fy));
                    pSprite->setRotation(s_spi7[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("7.png");
                break;
            case CRDN_N8:
                nCardNum = 8;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi8[i].fx,s_spi8[i].fy));
                    pSprite->setRotation(s_spi8[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("8.png");
                break;
            case CRDN_N9:
                nCardNum = 9;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi9[i].fx,s_spi9[i].fy));
                    pSprite->setRotation(s_spi9[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("9.png");
                break;
            case CRDN_N10:
                nCardNum = 10;
                for (int i = 0; i < nCardNum; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spi10[i].fx,s_spi10[i].fy));
                    pSprite->setRotation(s_spi10[i].fRotate);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("10.png");
                break;
            case CRDN_J:
                nCardNum = 11;
                if (type == CRDG_HEART || type == CRDG_DIAMOND) {
                    centerImgName = "Cards/red_j.png";
                }
                else if(type == CRDG_SPADE || type == CRDG_CLUB)
                {
                    centerImgName = "Cards/black_j.png";
                }
                for (int i = 0; i < 1; i++) {
                    CCSprite* pSprite = NtfCreateSprite(centerImgName.c_str());
                    if (i == 0) {
                        pSprite->setAnchorPoint(ccp(0.5, 0.5));
                    }
                    else
                    {
                        pSprite->setAnchorPoint(ccp(0.5, 0));
                    }
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pForeBg->addChild(pSprite);
                }
                
                for (int i = 2; i < 4; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pSprite->setScale(0.8f);
                    pForeBg->addChild(pSprite);
                }
                
                numImgName.append("j.png");
                break;
            case CRDN_Q:
                nCardNum = 12;
                if (type == CRDG_HEART || type == CRDG_DIAMOND) {
                    centerImgName = "Cards/red_q.png";
                }
                else if(type == CRDG_SPADE || type == CRDG_CLUB)
                {
                    centerImgName = "Cards/black_q.png";
                }
                for (int i = 0; i < 1; i++) {
                    CCSprite* pSprite = NtfCreateSprite(centerImgName.c_str());
                    if (i == 0) {
                        pSprite->setAnchorPoint(ccp(0.5, 0.5));
                    }
                    else
                    {
                        pSprite->setAnchorPoint(ccp(0.5, 0));
                    }
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pForeBg->addChild(pSprite);
                }
                for (int i = 2; i < 4; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pSprite->setScale(0.8f);
                    pForeBg->addChild(pSprite);
                }
                
                numImgName.append("q.png");
                break;
            case CRDN_K:
                nCardNum = 13;
                if (type == CRDG_HEART || type == CRDG_DIAMOND) {
                    centerImgName = "Cards/red_k.png";
                }
                else if(type == CRDG_SPADE || type == CRDG_CLUB)
                {
                    centerImgName = "Cards/black_k.png";
                }
                for (int i = 0; i < 1; i++) {
                    CCSprite* pSprite = NtfCreateSprite(centerImgName.c_str());
                    if (i == 0) {
                        pSprite->setAnchorPoint(ccp(0.5, 0.5));
                    }
                    else
                    {
                        pSprite->setAnchorPoint(ccp(0.5, 0));
                    }
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pForeBg->addChild(pSprite);
                }
                for (int i = 2; i < 4; i++) {
                    CCSprite* pSprite = NtfCreateSprite(imageName.c_str());
                    pSprite->setPosition(ccp(s_spiS[i].fx,s_spiS[i].fy));
                    pSprite->setRotation(s_spiS[i].fRotate);
                    pSprite->setScale(0.8f);
                    pForeBg->addChild(pSprite);
                    
                }
                
                numImgName.append("k.png");
                break;
                
            default:
                break;
        }
        //添加牌型数字
        if (isShowNum) {
            for (int i = 0; i < 2; i++) {
                CCSprite* pSprite = NtfCreateSprite(numImgName.c_str());
                pSprite->setPosition(ccp(s_spiNumPos[i].fx,s_spiNumPos[i].fy));
                pSprite->setRotation(s_spiNumPos[i].fRotate);
                pForeBg->addChild(pSprite);
            }
        }
        
        return pForeBg;
    }
    
    
    void PageTurn2::onEventDone(int event, void *data)
    {
        if (event == EventTurnCard) {
            CTurnCrd* pTurnCrd = static_cast<CTurnCrd*>(data);
            if (pTurnCrd) {
                if (pTurnCrd->mRubAc != g_pSelf->GetValue(RVT_ACC_ID) && !mbIsFliped) {
                    if (pTurnCrd->mPlace == Horizontal)
                    {
                        mCardShowType = Horizontal;
                        m_pForeSprite->setVisible(false);
                        m_pForeSpriteMirror->setVisible(true);
                        m_pBgSprite->setVisible(false);
                        m_pBgSpriteMirror->setVisible(true);
                        
                        m_pForeSpriteVertical->setVisible(false);
                        m_pForeSpriteMirrorVertical->setVisible(false);
                        m_pBgSpriteVertical->setVisible(false);
                        m_pBgSpriteMirrorVertical->setVisible(false);
                        
                        if (!m_pBgSprite->isVisible()) {
                            m_pBgSprite->setVisible(true);
                            m_pBgSpriteMirror->setVisible(false);
                        }
                        if (!m_pForeSprite->isVisible()) {
                            m_pForeSprite->setVisible(true);
                            m_pForeSpriteMirror->setVisible(false);
                        }
                        
                        calculateHorizontalVertexPoints(pTurnCrd->mOffset / cosf(M_PI / 4),true);
                        judgeIsFlipCard(pTurnCrd->mOffset / cosf(M_PI / 4),mCardShowType,false);
                    }
                    else
                    {
                        mCardShowType = VerticalA;
                        m_pForeSprite->setVisible(false);
                        m_pForeSpriteMirror->setVisible(false);
                        m_pBgSprite->setVisible(false);
                        m_pBgSpriteMirror->setVisible(false);
                        
                        m_pForeSpriteVertical->setVisible(false);
                        m_pForeSpriteMirrorVertical->setVisible(true);
                        m_pBgSpriteVertical->setVisible(false);
                        m_pBgSpriteMirrorVertical->setVisible(true);
                        
                        if (!m_pBgSpriteVertical->isVisible()) {
                            m_pBgSpriteVertical->setVisible(true);
                            m_pBgSpriteMirrorVertical->setVisible(false);
                        }
                        if (!m_pForeSpriteVertical->isVisible()) {
                            m_pForeSpriteVertical->setVisible(true);
                            m_pForeSpriteMirrorVertical->setVisible(false);
                        }
                        
                        calculateVerticalVertexPoints(pTurnCrd->mOffset / cosf(M_PI / 4));
                        judgeIsFlipCard(pTurnCrd->mOffset / cosf(M_PI / 4),mCardShowType,false);
                    }
                    
                }
            }
        }
        else if (event == EventOpenAddTableView)
        {
            CCTouchDispatcher* td = CCDirector::sharedDirector()->getTouchDispatcher();
            if (mpMenu) {
                td->setPriority(10000, mpMenu);
            }
            if (mpHideBtn) {
                td->setPriority(10000, mpHideBtn);
            }
        }
        else if (event == EventCloseAddTableView)
        {
            CCTouchDispatcher* td = CCDirector::sharedDirector()->getTouchDispatcher();
            if (mpMenu) {
                td->setPriority(0, mpMenu);
            }
            if (mpHideBtn) {
                td->setPriority(0, mpHideBtn);
            }
    
        }
        else if(event == EventUpdateAvatar)
        {
            EVENT_UPDATEAVATAR_DATA* peud = (EVENT_UPDATEAVATAR_DATA*)data;
            if (!peud) {
                return;
            }
            if (peud->nAccId == g_pSelf->GetValue(RVT_ACC_ID)) {
                CCNode* pAvatar = this->getChildByTag(TAG_AVATAR);
                if (pAvatar) {
                    pAvatar->removeFromParent();
                }
                CCSize winSize = CCDirector::sharedDirector()->getWinSize();
                CCSprite* sprite = CCSprite::createWithTexture(peud->texture);
                CCClippingNode* clipA = NtfSetHeadIcon(sprite, CCSize(56, 56));
                clipA->setAnchorPoint(ccp(0.5, 0.5));
                clipA->setPosition(ccp(60, winSize.height - 118));
                this->addChild(clipA, 30,TAG_AVATAR);
            }
            
            
            
        }
        
    }
    
    void PageTurn2::onFlipAnimFinished(cocos2d::CCNode *pNode)
    {
    //    CMsgTurnCrd::PostToSever(mBacId,g_pSelf->GetValue(RVT_ACC_ID), mCurType, mCurNum, TurnOver, 0);
    //    
    //    mCurIndex++;
        
        
        if (mCurIndex < mPickAry.size()) {
            
            CCNode* node = (CCNode*)getChildByTag(mCurIndex);
            if (node) {
                node->removeFromParentAndCleanup(true);
                cocos2d::extension::CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("BuilderAnimate/fanpaidonghuazuixin0.png", "BuilderAnimate/fanpaidonghuazuixin0.plist", "BuilderAnimate/fanpaidonghuazuixin.ExportJson");
                CCArmature* armatureTriangle = cocos2d::extension::CCArmature::create("fanpaidonghuazuixin");
                armatureTriangle->setAnchorPoint(ccp(0.5, 0.5));
                armatureTriangle->setPosition(ccp(pos[mCurIndex].fx, pos[mCurIndex].fy));
                armatureTriangle->getAnimation()->playWithIndex(0);
                this->addChild(armatureTriangle,1,mCurIndex);
            }
            
            if (m_pForeSprite) {
                m_pForeSprite->removeFromParentAndCleanup(true);
            }
            if (m_pForeSpriteMirror) {
                m_pForeSpriteMirror->removeFromParentAndCleanup(true);
            }
            if (m_pBgSprite) {
                m_pBgSprite->removeFromParentAndCleanup(true);
            }
            if (m_pBgSpriteMirror) {
                m_pBgSpriteMirror->removeFromParentAndCleanup(true);
            }
            if (m_pForeSpriteVertical) {
                m_pForeSpriteVertical->removeFromParentAndCleanup(true);
            }
            if (m_pForeSpriteMirrorVertical) {
                m_pForeSpriteMirrorVertical->removeFromParentAndCleanup(true);
            }
            if (m_pBgSpriteVertical) {
                m_pBgSpriteVertical->removeFromParentAndCleanup(true);
            }
            if (m_pBgSpriteMirrorVertical) {
                m_pBgSpriteMirrorVertical->removeFromParentAndCleanup(true);
            }
            if (m_pShowPokerCard) {
                m_pShowPokerCard->removeFromParentAndCleanup(true);
            }
            mCardShowType = Horizontal;
            createPokerSprite(mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum);
            mFlipDemoOffset = 0;
            schedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
            mbIsFliped = false;
        }
        else
        {
            g_stage->mFlipProgress[mTableId] = 0;
            removeFromParentAndCleanup(true);
            EventManager::sharedEventManager()->notifyEventFinished(EventShowLastThreeCard);
        }
    }
    
    void PageTurn2::judgeIsFlipCard(float offset,CardShowType showType,bool flag)
    {
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        //判断是否已经翻牌了
        if ((((showType == Horizontal || showType == Horizontal2) && offset > (winSize.width/2 + 250)) || ((showType == VerticalA || showType == VerticalE) && offset > winSize.height/2 + 250)) && !mbIsFliped) {
            mbIsFliped = true;
            
            unschedule(schedule_selector(PageTurn2::onFlipDemoUpdate));
            m_pBgSprite->setVisible(false);
            m_pForeSprite->setVisible(false);
            m_pBgSpriteVertical->setVisible(false);
            m_pForeSpriteVertical->setVisible(false);
            m_pBgSpriteMirror->setVisible(false);
            m_pForeSpriteMirror->setVisible(false);
            m_pBgSpriteMirrorVertical->setVisible(false);
            m_pForeSpriteMirrorVertical->setVisible(false);
            
            //添加盘牌动画
            m_pShowPokerCard = createPokerCard(mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum,true);
            m_pShowPokerCard->setAnchorPoint(ccp(0.5, 0.5));
            m_pShowPokerCard->setPosition(ccp(winSize.width/2, winSize.height/2));
            this->addChild(m_pShowPokerCard,2);
            m_pShowPokerCard->setScale(2.0f);
            
            CCScaleTo* scale = CCScaleTo::create(0.1f, 1.0f);
            CCDelayTime* delay = CCDelayTime::create(2.0f);
            CCArray* ary = CCArray::create();
            
            ary->addObject(scale);
            ary->addObject(delay);
            if (flag) {
                SEL_CallFuncN func = callfuncN_selector(PageTurn2::onFlipAnimFinished);
                ary->addObject(CCCallFuncN::create(this, func));
            }
            CCSequence* action = CCSequence::create(ary);
            m_pShowPokerCard->runAction(action);
            
        
            
    
            String imgName = GetCardFace(mPickAry[mCurIndex].mGrp, mPickAry[mCurIndex].mNum);
            CCNode* node = (CCNode*)getChildByTag(mCurIndex);
            if (node) {
                node->removeFromParentAndCleanup(true);
                CCSprite* sprite = NtfCreateSprite(imgName.c_str());
                sprite->setPosition(ccp(pos[mCurIndex].fx,pos[mCurIndex].fy));
                this->addChild(sprite,1,mCurIndex);
            }
            
            mCurIndex++;
            g_stage->mFlipProgress[mTableId] = mCurIndex;
        }
    }
    
    //--------------------------------------------------------------------------------
    bool PageTurn2::OnTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
    {
        ccTouchBegan(pTouch, pEvent);
    
        TouchLyr::iterator it = mTouchLyr.begin();
        while(it != mTouchLyr.end())
        {
            CRayLayer* vLyr = *it;
            if(vLyr->OnTouchBegan(pTouch, pEvent))
            {
                mCurLyr = vLyr;
                break;
            }
            ++it;
        }
        return true;
    }
    
    //--------------------------------------------------------------------------------
    bool PageTurn2::OnTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
    {
        ccTouchMoved(pTouch, pEvent);
        if (mCurLyr)
        {
            mCurLyr->OnTouchMoved(pTouch, pEvent);
        }
        return true;
    }
    
    //--------------------------------------------------------------------------------
    bool PageTurn2::OnTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
    {
        ccTouchEnded(pTouch, pEvent);
        if (mCurLyr)
        {
            mCurLyr->OnTouchEnded(pTouch, pEvent);
        }
        mCurLyr = NULL;
        return true;
        
    }
    
    

     

     

     

        float deltaAy = (tt * tt *500);

        float ay = -100 - deltaAy;

        

        float deltaTheta = - (float)M_PI_2 *sqrtf( time) ;

        float theta =/*0.01f */ + (float)M_PI_2 +deltaTheta;

        

        float sinTheta =sinf(theta);

        float cosTheta =cosf(theta);

        

        for (int i =0; i <=m_sGridSize.width; ++i)

        {

            for (int j =0; j <=m_sGridSize.height; ++j)

            {

               // Get original vertex

                ccVertex3F p = originalVertex(ccp(i ,j));

                

                float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay)));

                float r = R * sinTheta;

                float alpha = asinf( p.x / R );

                float beta = alpha / sinTheta;

                float cosBeta = cosf( beta );

                

               // If beta > PI then we've wrapped around the cone

               // Reduce the radius to stop these points interfering with others

                if (beta <= M_PI)

                {

                    p.x = ( r *sinf(beta));

                }

                else

                {

                   // Force X = 0 to stop wrapped

                    // points

                    p.x =0;

                }

     

                p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));

     

               // We scale z here to avoid the animation being

               // too much bigger than the screen due to perspective transform

                p.z = (r * (1 - cosBeta ) * cosTheta) /7;// "100" didn't work for

     

               //    Stop z coord from dropping beneath underlying page in a transition

               // issue #751

                if( p.z < 0.5f )

                {

                    p.z =0.5f;

                }

                

               // Set new coords

                setVertex(ccp(i, j), p);

                

            }

        }

    }

    刚开始看这个,完全不知所云,一堆三角函数,抓狂,简直了,后来找了好久,找到一篇论文

    正好把源码解释得一清二楚,论文的链接为:http://www.parc.com/content/attachments/turning-pages-3D.pdf

     

     

     

    看完之后才明白,原来是建立了一个数学模型,通过数学模型去计算每个顶点在变换过程中的位置,明白了。到现在才理解大学时老师说的那句话,数学对编程来说很重要。

     

    回到主题,我们要实现的是类似翻书的效果,通过上面的算法,得到的效果和我的需求有点差异,既然他是想象成一个锥体的运到,我们可以想象成一个圆柱体的运到,通过改变圆柱体轴心的位置,来实现翻动的效果,不多说了,直接上源码:

     

    voidPageTurn::calculateHorizontalVertexPoints(float offsetX)

    {

        float theta = (GLfloat)(M_PI /6.0f);

        float R =50;

        float b = (m_pBgSprite->getContentSize().width - offsetX *1.4f) * sinf(theta);

        

        

        

        for (int i =0; i <=m_sGridSize.width; ++i)

        {

            for (int j =0; j <=m_sGridSize.height; ++j)

            {

               // Get original vertex

               ccVertex3F p =originalVertex(ccp(i ,j),m_pForeSprite);

                

                float x = (p.y + b) / tanf(theta);

                

                float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);

                float pivotY = pivotX * tanf(theta) - b;

                

                float l = (p.x - pivotX) / sinf(theta);

                float alpha = l / R;

                if (l >= 0) {

                    if (alpha > M_PI) {

                        p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha -M_PI) * sinf(theta));

                        p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha -M_PI) * cosf(theta));

                        p.z = (GLfloat)(2 * R /9);

                    }

                    else if (alpha <= M_PI)

                    {

                        p.x = (GLfloat)(mHOffsetX + pivotX + R *sinf(alpha) *sinf(theta));

                        p.y = (GLfloat)(mHOffsetY + pivotY - R *sinf(alpha) *cosf(theta));

                        p.z = (GLfloat)((R - R *cosf(alpha))/9);

                    }

                }

                else

                {

                    p.x +=mHOffsetX;

                    p.y +=mHOffsetY;

                }

                

               // Set new coords

                setVertex(ccp(i, j), p,m_pForeSprite);

                

                

            }

        }

        

        for (int i =0; i <=m_sGridSize.width; ++i)

        {

            for (int j =0; j <=m_sGridSize.height; ++j)

            {

               // Get original vertex

               ccVertex3F p =originalVertex(ccp(i ,j),m_pBgSprite);

                float x = (p.y + b) / tanf(theta);

                

                float pivotX = x + (p.x - x) * cosf(theta) * cosf(theta);

                float pivotY = pivotX * tanf(theta) - b;

                

                float l = (p.x - pivotX) / sinf(theta);

                float alpha = l / R;

                if (l >= 0) {

                    if (alpha > M_PI) {

                        p.x = (GLfloat)(mHOffsetX + pivotX - R * (alpha -M_PI) * sinf(theta));

                        p.y = (GLfloat)(mHOffsetY + pivotY + R * (alpha -M_PI) * cosf(theta));

                        p.z = (GLfloat)(2 * R /9);

                    }

                    else if (alpha <= M_PI)

                    {

                        p.x = (GLfloat)(mHOffsetX + pivotX + R *sinf(alpha) *sinf(theta));

                        p.y = (GLfloat)(mHOffsetY + pivotY - R *sinf(alpha) *cosf(theta));

                        p.z = (GLfloat)((R - R *cosf(alpha))/9);

                    }

                }

                else

                {

                    p.x +=mHOffsetX;

                    p.y +=mHOffsetY;

                }

                

                setVertex(ccp(i, j), p,m_pBgSprite);

                

                

                

            }

        }

        

        //    float R2 = 50;

        //    float offsetX2 = mTouchBegin.x - pTouch->getLocation().x;

        //    float pivotX2 = m_pForeSpriteVertical->getContentSize().height - offsetX2;

        //

        //

        //    for (int i = 0; i <= m_sGridSize.width; ++i)

        //    {

        //        for (int j = 0; j <= m_sGridSize.height; ++j)

        //        {

        //            // Get original vertex

        //            ccVertex3F p = originalVertex(ccp(i ,j),m_pForeSpriteVertical);

        //            float l = p.x - pivotX2;

        //            float alpha = l / R2;

        //            if (l >= 0) {

        //                if (alpha > M_PI) {

        //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);

        //                    p.z = 2 * R2 / 9;

        //                    p.y = p.y + mVOffsetY;

        //                }

        //                else if (alpha <= M_PI)

        //                {

        //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);

        //                    p.z = (R2 - R2 * cosf(alpha))/9;

        //                    p.y = p.y + mVOffsetY;

        //                }

        //            }

        //            else

        //            {

        //                p.x = p.x + mVOffsetX;

        //                p.y = p.y + mVOffsetY;

        //            }

        //

        //

        //            // Set new coords

        //            setVertex(ccp(i, j), p,m_pForeSpriteVertical);

        //

        //

        //        }

        //    }

        //

        //    for (int i = 0; i <= m_sGridSize.width; ++i)

        //    {

        //        for (int j = 0; j <= m_sGridSize.height; ++j)

        //        {

        //            // Get original vertex

        //            ccVertex3F p = originalVertex(ccp(i ,j),m_pBgSpriteVertical);

        //            float l = p.x - pivotX2;

        //            float alpha = l / R2;

        //            if (l >= 0) {

        //                if (alpha > M_PI) {

        //                    p.x = mVOffsetX + pivotX2 - R2 * (alpha - M_PI);

        //                    p.z = 2 * R2 / 9;

        //                    p.y = p.y + mVOffsetY;

        //                }

        //                else if (alpha <= M_PI)

        //                {

        //                    p.x = mVOffsetX + pivotX2 + R2 * sinf(alpha);

        //                    p.z = (R2 - R2 * cosf(alpha))/9;

        //                    p.y = p.y + mVOffsetY;

        //                }

        //            }

        //            else

        //            {

        //                p.x = p.x + mVOffsetX;

        //                p.y = p.y + mVOffsetY;

        //            }

        //

        //            // Set new coords

        //            setVertex(ccp(i, j), p,m_pBgSpriteVertical);

        //            

        //            

        //            

        //        }

        //    }

    }

    3d节点的渲染我用的是CCGridBase的子类CCGrid3D,只需要把CCGrid3DAction中渲染的部分摘出来即可,代码在cocos中都有(补充下,我用的是cocos2dx2.2.6),以下是最终效果:

     

     

     

    展开全文
  • cocos2dx - PageView

    2019-07-04 17:04:03
    Cocos2dx PageView 可以使用翻页的效果 创建PageView: Size size(150, 130); PageView* pageView = PageView::create(); pageView->setDirection(PageView::Direction::HORIZONTAL); pageView->...

    Cocos2dx PageView 可以使用翻页的效果

     创建PageView:

    Size size(150, 130);
    PageView* pageView = PageView::create();
    pageView->setDirection(PageView::Direction::HORIZONTAL);
    pageView->setContentSize(size);
    Size backgroundSize = bg->getContentSize();
    pageView->setPosition(Vec2(origin.x+ 10,origin.y+50));
    pageView->removeAllItems();
    pageView->setIndicatorEnabled(true);
    pageView->setGlobalZOrder(200);
    this->addChild(pageView);
    

    初始化数据:

    int pageCount = 4;
    for (int i = 0; i < pageCount; ++i)
    {
        Layout* layout = Layout::create();
        layout->setContentSize(size);
    
        ImageView* imageView = ImageView::create("YellowSquare.png");
        imageView->setScale9Enabled(true);
        imageView->setContentSize(size);
        imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
        layout->addChild(imageView);
    
        Text* label = Text::create(StringUtils::format("page %d",(i)), "fonts/Marker Felt.ttf", 30);
        label->setColor(Color3B(192, 192, 192));
        label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
        layout->addChild(label);
        pageView->insertCustomItem(layout, i);
    
    }
    pageView->setIndicatorIndexNodesOpacity(255);

    添加翻页监听:

    pageView->addEventListener([this,pageView](Ref *sender, PageView::EventType type) {
        switch (type) {
            case cocos2d::ui::PageView::EventType::TURNING:
                int pageIndex = pageView->getCurrentPageIndex();
                break;
        }
    });
    

    效果图如下:

     

    展开全文
  • 在使用cocos 2d-x开发过程中,我们肯定会用到一些滑动类的容器,常见的容器类PageView,ScrollView,TableView.就挨个介绍一下吧。 首先介绍一下ScrollView,怎么说呢,以前没经常使用,最近好好研究了一下,cc....
  • cocos 2d-x 中“容器”就是一个节点,但是又有不同于节点的特殊属性。 本文主要是我在做邮件界面时用到滚动容器的介绍和一些问题 1、初始化 auto ScrollViewEmail = dynamic_cast&lt;ui::ScrollView*&...
  • ListView列表容器,看到名字我们就知道它有子控件布局。ScrollView可以成为ListView,怎么做呢?利用ScrollView的子控件布局的横向布局,纵向布局。实际开发游戏ListView基本不用,当ListView的内容比较多时,会出现...
  • ---pageView  local page=ccui.PageView:create()  for i=1,8 do ---创建layout,内容添加到layout  local layout=ccui.Layout:create()  layout:setContentSize(700,700) ... 
  • cocos2dx-ui的分类与使用
  • PageVIew实现翻页的效果 使用cocos2d-lua社区版 local MainScene = class("MainScene", function() return display.newScene("MainScene") end) function MainScene:ctor() local layer = cc.LayerColor:...
  • 这是Cocos2dx最简单的部分。主要是体现对场景的操作,其实这东西就是Flash的舞台,安卓的Activity,WIN32窗体程序的Framework窗体,网页的body,反正就是对那个容纳各种东西的大容器进行操作,爱怎么叫就怎么叫。 ...
  • 相关文件夹: cocostudio--解析 ui--控件 查找方式: ...首先在cocostudio里的reader里找到对应的reader,可以找到各种属性以及载入方式,然后到ui里找到对应的控件类,可以找到该控件的各种功能实现 ...
  • cocos2dx 示例 笔记

    2015-07-21 18:33:50
    首先是头文件,此笔记是整合在一起的, 不同类别用/*****/分开了 ...#include "cocos2d.h" //#include //引入这玩意 需要在配置 C++ -- 常规 --包含引用目录后添加 $(EngineRoot) 使用tableView需要引入此头
  • 今天, 我们来看看场景CCScene的创建原理和切换方式
  • 最近工作中要使用CocosStudio做界面尴尬,好吧,不管对他有什么偏见,学习一下吧。这里主要记录一下三个控件的使用和说明。就是ScrollView,ListView和PageView。 首先大致的介绍一下这三个控件吧
  • cocos2d-js PageView用法

    2017-09-02 15:44:51
    1.在cocos studio里面 翻页容器,然后右击翻页容器,添加子控件,子控件类型必须为Layout,不然无法添加。 2.代码中添加这个获取这个翻页容器:this.pageView = this.node.getChildByName("pageView"); 3.this....
  • 发现如果在cocos studio里操作给PageView创建页面元素时,即使setIndicatorEnabled为true也看到下方的指示点,必须调用addWidgetToPage或者insertPage才可以,但是懒的用代码来堆UI,所以在studio里把还是把页面元素...
  •  (2)滚动方向  &gt; CCScrollViewDirection 改为强枚举 ScrollView::Direction // HORIZONTAL //只能横向滚动 VERTICAL //只能纵向滚动 BOTH //横向纵向都能滚动,默认方式 //  ...
  • 2013-03-09 Legend 使用plist文件添加动画 //【addAction】 CCAnimation* animation = HelloWorld::BuilderAnimation("Boss1.plist","Boss1_attack_%02d.png",1,5); animation->setLoops(-1);...
1 2 3 4
收藏数 77
精华内容 30
关键字:

2dx翻页容器 cocos