少年啊,来一发昆特吗(二)——昆特牌的触摸

昆特牌在整个游戏中需要三种触摸形式,一种是初始发牌时的换牌阶段,点击可以更换牌(镶嵌到tableview中),二是正常打牌阶段的触摸,点击两次后,将牌打出,第三种是医生的复活技能效果,选择墓地中的牌将其复活到场上,所以在上一节使用了3种触摸函数来达成这三种效果,以及npc的禁止点击的种类,所以采用了在onEnter中通过所需要的BType的值来确定触摸函数

void GWentCard::onEnter(){
    CCLayer::onEnter();//一定要用基类的onEnter,否则可能出现各种问题
    //触摸响应注册
    touchListener = EventListenerTouchOneByOne::create();//创建单点触摸事件监听器
    this->setTouchEnabled(true);
    //当为0时就使用如下触摸
    if(Spritetype==0){
      touchListener->onTouchBegan = CC_CALLBACK_2(GWentCard::onTouchBegan, this);//触摸开始
      touchListener->onTouchMoved = CC_CALLBACK_2(GWentCard::onTouchMoved, this);//触摸移动
      touchListener->onTouchEnded = CC_CALLBACK_2(GWentCard::onTouchEnded, this);//触摸结束
      touchListener->setSwallowTouches(false);//不向下吞并触摸
      _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);//注册分发器
    }else if(Spritetype==1){
       touchListener->onTouchBegan = CC_CALLBACK_2(GWentCard::onTouchBeganSelect, this);//触摸开始
       touchListener->onTouchMoved = CC_CALLBACK_2(GWentCard::onTouchMovedSelect, this);//触摸移动
       touchListener->onTouchEnded = CC_CALLBACK_2(GWentCard::onTouchEndedSelect, this);//触摸结束
       touchListener->setSwallowTouches(false);//不向下吞并触摸
       _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);//注册分发器

    }else if(Spritetype==2){
         touchListener->onTouchBegan = CC_CALLBACK_2(GWentCard::onTouchBeganSelectGrave, this);//触摸开始
         touchListener->onTouchMoved = CC_CALLBACK_2(GWentCard::onTouchMovedSelectGrave, this);//触摸移动
         touchListener->onTouchEnded = CC_CALLBACK_2(GWentCard::onTouchEndedSelectGrave, this);//触摸结束
         touchListener->setSwallowTouches(false);//不向下吞并触摸
         _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);//注册分发器

    }else if(Spritetype==3){

    }
    String *pow=String::createWithFormat("%d",this->getNewPower());
    auto label=LabelTTF::create(pow->getCString(),"",50);
    label->setAnchorPoint(Point(0.5,0.5));
    label->setName("power");
    Size size=this->getContentSize();
    label->setPosition(Point(32,size.height-30));
    label->setColor(Color3B(255,0,0));
    this->addChild(label,1);
}

下面简要挑一个触摸函数来说明,下面的函数是为了在发牌阶段使用的触摸函数,主要目的是点击后进行换牌,cocos2dx的触摸流程在上一篇中已经介绍过了,这里就不多说了,因为这个函数是用在tableview上的,所以必须保证在滑动时不触发点击效果,保证方法很容易,也就是在began中不进行处理,在end中如果点击位置和在began中的位置一样时,就进行处理点击效果,因为滑动后处于end位置的点必然和初始点击位置不同,在初始保存点击位置,于end中获取结束位置,比较两者如果一致,就触发点击效果,否则就不处理,之后的过程就是常规的换牌过程,就不多作解释了


bool GWentCard::onTouchBeganSelect(CCTouch *pTouch, CCEvent *pEvent){
    firstPoint=pTouch->getLocation();
    return true;
}
void GWentCard::onTouchMovedSelect(CCTouch *pTouch, CCEvent *pEvent){


}
void GWentCard::onTouchEndedSelect(CCTouch *pTouch, CCEvent *pEvent){
    auto EndPoint=pTouch->getLocation();
    if(firstPoint!=EndPoint){
        return;
    }
    TableViewCell *cell=(TableViewCell *)this->getParent();
    TableViewCell *targetcell=(TableViewCell *)pEvent->getCurrentTarget()->getParent();
    int id=cell->getIdx();
    int idx=targetcell->getIdx();
    auto table=(TableView *)m_gameMain->getChildByTag(0);//cell需要获得两次parent才能拿到table
    CCPoint ptouch=table->convertToNodeSpaceAR(pTouch->getLocation());
    auto distance=(int)(ptouch.x-table->getContentOffset().x)/690;//获得点击的页数即第几个cell
    Size size=this->getContentSize();
    Point p=this->getPosition();
    CCRect rect(p.x,p.y,size.width,size.height);
    log("%f",table->getContentOffset().x);
    if(cell->getIdx()==distance){
       auto dis=(-(int)(table->getContentOffset().x))/690;
       auto s=-(int)(table->getContentOffset().x)-distance*690;
       //auto m=690-s;
       ptouch.x=ptouch.x+s;
      // log("minx=%d,miny=%d,maxx=%d,maxy=%d",this->getBoundingBox().getMinX(),this->getBoundingBox().getMinY(),this->getBoundingBox().getMaxX(),this->getBoundingBox().getMaxY());
       if(rect.containsPoint(ptouch)){
           Array *deckarr= m_gameMain->getDeckArray();//获取牌组数据
           Dictionary *dic=(Dictionary *)deckarr->randomObject();//获取一个随机数
            int time= m_gameMain->getRetime();
            time=time+1;
            m_gameMain->setRetime(time);
           GWentCard *card=GWentCard::create(dic);
           card->setBType(1);
           card->setPosition(this->getPosition());
           card->setGameMain(this->getGameMain());
           card->setAnchorPoint(Point::ZERO);
           deckarr->addObject(this->dictionary);//加入牌组中
           m_gameMain->getHandArray()->addObject(dic);//加入手牌中   
           m_gameMain->getHandArray()->removeObject(this->dictionary);//从手牌中删除
           m_gameMain->setSelect(false);
           deckarr->removeObject(dic);//从牌组中删除  

           cell->removeChild(this);
           cell->addChild(card);
           card->getGameMain()->updateretimeslabelinfo(0);
//         
          //将被点击卡重新加入牌组中,并从牌组中拿出一张卡
       }
    }
}
Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值