新手刚接触游戏编程,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(Cont