Cocos2d-x 3.3 动作游戏连续普通攻击判断
发布时间:2020-12-14 20:11:41 所属栏目:百科 来源:网络整理
导读:新手刚接触游戏编程,cocos2d-x做一个简单的横版战斗游戏Demo卡在普通攻击判断上。 花了一些时间和别人讨论理清逻辑写了这个代码。应该还有很多优化的地方。 发出来与大家分享下。 没理清逻辑的时候,真写不出来 void ContButton::touchBegan(){isTouch=true
新手刚接触游戏编程,cocos2d-x做一个简单的横版战斗游戏Demo卡在普通攻击判断上。 花了一些时间和别人讨论理清逻辑写了这个代码。应该还有很多优化的地方。 发出来与大家分享下。 没理清逻辑的时候,真写不出来 void ContButton::touchBegan() { isTouch=true;//按钮按下 this->schedule(schedule_selector(ContButton::updatelongprogress),1);//蓄力时间判断 //做连击判断 if(touchCounts==0) onSingleCLick(); if(touchCounts==1&&m_pHero->getAttackAction()->isDone()) onDoubleClick(); if(touchCounts==2&&m_pHero->getAttackActionB()->isDone()) onThreeClick(); if(touchCounts==3&&m_pHero->getAttackActionC()->isDone()) touchCounts=0; } void ContButton::touchEnded() { isTouch=false; pressTimes=0; this->unschedule(schedule_selector(ContButton::updatelongprogress)); //如果刚完成长按事件 则把按下次数清零 长按状态置空 直接返回 不继续执行 if (m_longProgress ) { touchCounts=0; m_longProgress=false; return; } this->scheduleOnce(schedule_selector(ContButton::updateAttackDelay),0.8); } void ContButton::onSingleCLick() { CCLOG("signle");//1连击 this->unschedule(schedule_selector(ContButton::updateAttackDelay)); m_pHero->runAttackAction(); touchCounts++; } void ContButton::onDoubleClick() { CCLOG("double"); //2连击 this->unschedule(schedule_selector(ContButton::updateAttackDelay)); m_pHero->runAttackActionB(); touchCounts++; } void ContButton::onThreeClick() { CCLOG("three"); //3连击 this->unschedule(schedule_selector(ContButton::updateAttackDelay)); m_pHero->runAttackActionC(); touchCounts++; } void ContButton::onLongPressed() { CCLOG("preassed");//长按 } void ContButton::updateAttackDelay(float ft) { touchCounts=0; } void ContButton::updatelongprogress(float ft) { if (isTouch) { pressTimes++; if (pressTimes >= 2) { m_longProgress=true; onLongPressed(); } } else { pressTimes=0; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |