• 从tableview中拖动某个精灵


        virtual void                                    registerWithTouchDispatcher(void);
        virtual bool                                    ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent);
        virtual void                                    ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent);
        virtual void                                    ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent);
    
        virtual void                                    tableCellHighlight(CCTableView* table, CCTableViewCell* cell);
    //设置成-1让它的层级降低这样就可以优先被触发
    //这样就会先执行touchbegain再执行tableCellHighlight
    void CCardlayer::registerWithTouchDispatcher(void)
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -1, false); 
    }
    bool CCardlayer::ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent)
    {
        switch (m_eClickTable)
        {
        case CCardlayer::CARD_TABLE_EQUIP_TAG:
            {
                if (m_nClickIndex != 0)
                    return false;
            }
            break;
        case CCardlayer::CARD_TABLE_GENERAL_TAG:
            {
                if (m_nClickIndex != 1)
                    return false;
            }
            break;
        case CCardlayer::CARD_TABLE_TRAP_TAG:
            {
                if (m_nClickIndex != 2)
                    return false;
            }
            break;
        default:
            break;
        }
    
        m_pTouchLocation = pTouch; //设置该函数优先触发主要是为了获取到这个变量
        
        return true;
    }
    void CCardlayer::tableCellHighlight(CCTableView* table, CCTableViewCell* cell)
    {
        m_tPos = cell->convertTouchToNodeSpace(m_pTouchLocation);
        for (int i = 0; i < 2; ++i)
        {
            CCSprite* pFrame = (CCSprite*)cell->getChildByTag(CARD_CELL_BTN_LEFT_TAG + i);
            CC_ERROR(pFrame, "【CCardlayer::tableCellHighlight】 pFrame 为空");
            if(pFrame->boundingBox().containsPoint(m_tPos))
            {
                UINT unIndex = cell->getIdx();
                m_nMoveIdx = unIndex * RIGHT_CELL_BTN_AMOUNT + i;
                this->LoadMove();
                return;
            }
        }
    }
    void CCardlayer::LoadMove()
    {
        std::string g_ImgPath(CGlobalMgr::GetInstance()->GetResourcesEx());
        std::string strPath;
        const Item_Info* pInfo = NULL;
        const CEudemon* pEudemon = NULL;
        
        CCSprite* pImgMove = NULL;
        
        switch (m_eClickTable)
        {
        case CCardlayer::CARD_TABLE_EQUIP_TAG:
            {
                pInfo = m_pPackageMgr->QueryEquipById(m_nMoveIdx);
                CC_ERROR(pInfo, "【CCardlayer::LoadMove】pInfo 为空")
                CCString* pStrImgMove = CCString::createWithFormat("%d", pInfo->nImageIdx);
                CC_ERROR(pStrImgMove, "【CCardlayer::LoadMove】pStrImgMove 为空")
                strPath = g_ImgPath + pStrImgMove->getCString() + ".png";
                pImgMove = CCSprite::create(strPath.c_str());
            }
            break;
        case CCardlayer::CARD_TABLE_GENERAL_TAG:
            {
                pEudemon = m_pCardMgr->QueryEudemonByIndex(m_nMoveIdx);
                CC_ERROR(pEudemon, "【CCardlayer::LoadMove】pEudemon 为空")
                CCString* pStrImgMove = CCString::createWithFormat("%d", pEudemon->GetLookFace());
                CC_ERROR(pStrImgMove, "【CCardlayer::LoadMove】pStrImgMove 为空")
                strPath = g_ImgPath + pStrImgMove->getCString() + ".png";
                pImgMove = CCSprite::create(strPath.c_str());
            }
            break;
        case CCardlayer::CARD_TABLE_TRAP_TAG:
            {
                pInfo = m_pPackageMgr->QueryEquipById(m_nMoveIdx);
                CCString* pStrImgMove = CCString::createWithFormat("%d", pInfo->nImageIdx);
                CC_ERROR(pStrImgMove, "【CCardlayer::LoadMove】pStrImgMove 为空")
                strPath = g_ImgPath + pStrImgMove->getCString() + ".png";
                pImgMove = CCSprite::create(strPath.c_str());
            }
            break;
        default:
            break;
        }
        CC_ERROR(pImgMove, "【CCardlayer::LoadMove】pImgMove 为空")
        pImgMove->setPosition(m_tPos);
        pImgMove->setAnchorPoint(ccp(0.5, 0.5));
        pImgMove->setVisible(false);
        pImgMove->setTag(CARD_IMG_MOVE_TAG);
        this->addChild(pImgMove);
    }
    void CCardlayer::ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent)
    {
        CCSprite* pImgMove = (CCSprite*)this->getChildByTag(CARD_IMG_MOVE_TAG);
        CC_ERROR(pImgMove, "【CCardlayer::ccTouchMoved】pImgMove为空")
        pImgMove->setVisible(true);
        pImgMove->setPosition(pTouch->getLocation());
    }
    
    void CCardlayer::ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent)
    {
        CCPoint tPos = pTouch->getLocation();
        if ((tPos.x >= RIGHT_RECT_START_X && tPos.x <= RIGHT_RECT_START_X + RIGHT_RECT_WIDTH) 
            && (tPos.y >= RIGHT_RECT_START_Y && tPos.y <= RIGHT_RECT_START_Y + RIGHT_RECT_HEIGH))
        {
    
        }
    
        this->removeChildByTag(CARD_IMG_MOVE_TAG);
    }
  • 相关阅读:
    提交订单的时候,实现拦截,登录成功后跳转回之前的页面;使用redis生成指定起始位置的id
    iOS Outlets Referencing Outlets
    iOS 常用控件 参数
    iOS UIImageView设置为圆形
    iOS Xcode个人常用插件
    iOS Xcode注释的几种使用方法
    MFC MSBDutyTable下载地址
    MFC HTTP访问URL
    MFC 程序以管理员权限运行
    MFC 打开文件夹选择框并获取文件夹路径
  • 原文地址:https://www.cnblogs.com/newlist/p/3504791.html
Copyright © 2020-2023  润新知