• 实习小白::cocos2d-x 2.2 study ---------- 长按事件处理


    cocos2d-x 2.2 study    ----------    长按事件处理

    其实是在点击事件发生的时候,

    在开始的时候添加一个一次的计时器,

    在计时器中添加方法,

    在结束的时候将添加的内容移除掉

    代码:(主要代码)

     1 void    GetFirstRechargePackLayer::menuEvent(CCObject* pSender, cocos2d::ui::TouchEventType type)
     2 {
     3     switch (type)
     4     {
     5     case TOUCH_EVENT_BEGAN:
     6         {
     7             if ( pSender == m_pImage4)
     8                 m_materialType = EP_HERO;
     9             else
    10                 m_materialType = EP_ITEM;
    11             m_isLongClick = false;
    12             m_icon = pSender;
    13             touchBeginPoint = ((cocos2d::ui::UIImageView*)pSender)->getTouchStartPos();
    14             this->scheduleOnce(schedule_selector (GetFirstRechargePackLayer::createTipLayer),0.2);
    15         }
    16         break;
    17     case TOUCH_EVENT_MOVED:
    18         {
    19             touchMovedPoint = ((cocos2d::ui::UIImageView*)pSender)->getTouchMovePos();
    20             float distance = sqrt((touchMovedPoint.x-touchBeginPoint.x) * (touchMovedPoint.x-touchBeginPoint.x) + (touchMovedPoint.y-touchBeginPoint.y)*(touchMovedPoint.y-touchBeginPoint.y));
    21 
    22             if (distance >= 50)
    23             {
    24                 this->unschedule(schedule_selector (GetFirstRechargePackLayer::createTipLayer));
    25             }
    26         }
    27         break;
    28     case TOUCH_EVENT_ENDED:
    29         {
    30             this->unschedule(schedule_selector (GetFirstRechargePackLayer::createTipLayer));
    31             if (m_isLongClick == true)
    32             {
    33                 this->removeChild(m_pLayerTips);
    34             }
    35         }
    36         break;
    37     case TOUCH_EVENT_CANCELED:
    38         {
    39             this->unschedule(schedule_selector (GetFirstRechargePackLayer::createTipLayer));
    40             if (m_isLongClick == true)
    41             {
    42                 this->removeChild(m_pLayerTips);
    43             }
    44         }
    45         break;
    46     default:
    47         break;
    48     }
    49 }
    50 
    51 void GetFirstRechargePackLayer::createTipLayer(float dt)
    52 {
    53     m_isLongClick = true;
    54     // 参数:1->图片(所点击的那个图片),2->类型(图片的类型),3->id
    55     m_pLayerTips = DesriptionTips::create(m_icon,m_materialType,(long)((cocos2d::ui::UIImageView*)m_icon)->getUserData());
    56     
    57     this->addChild(m_pLayerTips);
    58 }
  • 相关阅读:
    jwt
    生成型神经网络
    使用Python获取当前Bing的背景图片并设置为Windows壁纸
    系列文章分类汇总
    网络通信知识地图
    手撕spring核心源码,彻底搞懂spring流程
    消息中间件MQ的学习境界和路线
    convert tree structure from database to json object
    TypeScript: miniProgram 获取用户信息
    miniProgram: 写首个页面结构
  • 原文地址:https://www.cnblogs.com/dudu580231/p/4975576.html
Copyright © 2020-2023  润新知