接上一篇Cocos2d-x 3.3 动作游戏连续普通攻击判断
改进一下代码,实现了顺序播放动画效果,但是无法做到在播放动画途中按下攻击键,实现"预读"下一个动作效果
voID Contbutton::update(float dt){ if(this->istouch) { if(touchflag) { touchflag=false; if(touchCounts==0)touchcounts=1; if(touchCounts==1)touchcounts=2; if(touchCounts==2)touchcounts=0; } } if(m_pHero->getNomalAttackA()->isDone()||m_pHero->getNomalAttackB()->isDone()||m_pHero->getNomalAttackC()->isDone()) {touchflag=true;cclOG("--------->%d",touchCounts);} if(touchcounts!=touchCounts) { if(touchcounts==1)onSingleClick(); if(touchcounts==2)ondoubleclick(); if(touchcounts==0)onThreeClick(); touchCounts=touchcounts; }}
改进2
voID Contbutton::update(float dt){ if(this->istouch) { if(touchflag) { touchflag=false; if(touchCounts==0)touchcounts=1; if(touchCounts==1)touchcounts=2; if(touchCounts==2)touchcounts=0; this->unschedule(schedule_selector(Contbutton::updateAttackDelay)); cclOG("--------->%d",touchCounts); } istouch=false; } if(m_pHero->getNomalAttackA()->isDone()||m_pHero->getNomalAttackB()->isDone()||m_pHero->getNomalAttackC()->isDone()) { touchflag=true; } if(touchcounts!=touchCounts) { if(touchcounts==1)onSingleClick(); if(touchcounts==2)ondoubleclick(); if(touchcounts==0)onThreeClick(); touchCounts=touchcounts; this->scheduleOnce(schedule_selector(Contbutton::updateAttackDelay),0.8f); }}再改,加入蓄力系统,完全实现效果,但是纯过程编程.希望继续优化
voID Contbutton::update(float dt){ if(touchcounts!=touchCounts) { if(touchflag) { if(touchcounts==1)onSingleClick(); touchflag=false; } if(m_pHero->getNomalAttackA()->isDone()) { if(touchcounts==2)ondoubleclick(); } if(m_pHero->getNomalAttackB()->isDone()) { if(touchcounts==0)onThreeClick(); } if(m_pHero->getNomalAttackC()->isDone()) { touchflag=true; } }}voID Contbutton::touchBegan(){ istouch=true;//按钮按下 this->schedule(schedule_selector(Contbutton::updatelongprogress),1);//蓄力时间判断 this->unschedule(schedule_selector(Contbutton::updateAttackDelay));//取消连击数变0延时 //做连击判断 if(touchCounts==0)touchcounts=1; if(touchCounts==1)touchcounts=2; if(touchCounts==2)touchcounts=0; cclOG("--------->%d",touchCounts);}voID Contbutton::touchended(){ istouch=false; presstimes=0; this->unschedule(schedule_selector(Contbutton::updatelongprogress)); //如果刚完成长按事件 则把按下次数清零 长按状态置空 直接返回 不继续执行 if (m_longProgress ) { touchCounts=0; m_longProgress=false; onLongpressed(); return; } else { //判断是否为蓄力状态,是的话切换默认站立状态.蓄力失败 }}voID Contbutton::onSingleClick(){ cclOG("signle");//1连击 m_pHero->runNomalAttackA(); touchCounts=touchcounts; this->scheduleOnce(schedule_selector(Contbutton::updateAttackDelay),0.8f); //touchCounts++;} voID Contbutton::ondoubleclick(){ cclOG("double"); //2连击 m_pHero->runNomalAttackB(); touchCounts=touchcounts; this->scheduleOnce(schedule_selector(Contbutton::updateAttackDelay),0.5f);} voID Contbutton::onThreeClick(){ cclOG("three"); //3连击 m_pHero->runNomalAttackC(); touchCounts=touchcounts;} voID Contbutton::updateAttackDelay(float ft){ touchCounts=0; touchcounts=0; touchflag=true;}voID Contbutton::updatelongprogress(float ft){ if (istouch) { presstimes++; if(presstimes>0.5) { //放个蓄力动画什么的 //状态切换为蓄力状态 //连击延时计数最高也是0.5,所以不会冲突 if (presstimes >= 2) { m_longProgress=true; } } } else { presstimes=0; }}voID Contbutton::onLongpressed(){ cclOG("preassed");//长按 //使用蓄力招数}总结
以上是内存溢出为你收集整理的Cocos2d-x 3.3 动作游戏连续普通攻击判断-改进全部内容,希望文章能够帮你解决Cocos2d-x 3.3 动作游戏连续普通攻击判断-改进所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)