我要疯了——关于动作游戏普通攻击x3

:10:
基本上玩过动作游戏普通攻击也有很多个动作,我想实现这个效果但是卡在攻击次数&状态监测上
比如普通攻击1动作为A1,普通攻击第二招为A2,第三招为A3,蓄力招数为A4,都已经扔到动画缓存里了
之后是检测
这算法有问题啊,求帮助,有好点的算法么,蓄力的倒是实现了,而不同攻击没法实现类似DNF的效果……:10:
void ContButton::touchBegan()
{
isTouch=true;
//处理长按事件
this->schedule(schedule_selector(ContButton::updatelongprogress),1);
switch (touchCounts)
{
case 1:
this->scheduleOnce(schedule_selector(ContButton::updateDoubleDelay), 0.25);
onDoubleClick();
break;
case 2:
onThreeClick();
break;
default:
this->scheduleOnce(schedule_selector(ContButton::updateSingleDelay), 0.25);
onSingleCLick();
break;
}

}
void ContButton::touchEnded()
{
isTouch=false;
pressTimes=0;
this->unschedule(schedule_selector(ContButton::updatelongprogress));

//如果刚完成长按事件 则把按下次数清零 长按状态置空 直接返回 不继续执行
if (m_longProgress ) 
{
    touchCounts=0;
    m_longProgress=false;
    return;
}
//做连击判断
switch (touchCounts)
{
case 1:
    this->unschedule(schedule_selector(ContButton::updateSingleDelay));

    touchCounts++;
    //onDoubleClick();
    break;

case 2:        
    this->unschedule(schedule_selector(ContButton::updateDoubleDelay));
    //onThreeClick();
    touchCounts=0;
    break;

default:

    touchCounts++;
    //onSingleCLick();
    break;
}

}

没看明白到底想表达什么:904:,而且代码给我的感觉乱乱的。楼主请说清楚点

应该不是按照点击次数来判断下一个是动作吧?
应该是按照当前的动作来判定下一个动作。

是的,有个问题是当按下3次及3次以上时,前面几个动作还没有播放完,比如播放到第二个动作时候输入了第4次攻击的指令,结果下一次直接播放第一个攻击了。
由于我写的判断是到3次后,变成0.
这样写绝对有问题,求点思路

我想实现的是:按下攻击键,做出普通攻击动作
按一次播放动作1.
第二次播放动作2
第三次播放动作3
长按播放蓄力动画

上面的代码已经实现了蓄力动作的判定,但是对于按下次数的判断一点也不严格,造成动作混乱了。

void ContButton::updatelongprogress(float ft)
{
if (isTouch) {//按下状态
pressTimes++;//蓄力时间增加

    if (pressTimes >= 2) {//蓄力超过2秒
        m_longProgress=true;//蓄力完成
        onLongPressed();//播放蓄力攻击动画
    }
}
else
{
    pressTimes=0;//蓄力时间为0
}

}
补上一段蓄力攻击的代码

既然这样,那你先设一个状态变量,比如是int吧。当你每次点击的时候先判断int的值,值为1的话播放动作1.

动作1播放完后,把值设为2.下次点击的时候就会判断int的值为2,然后播放2…但是你这应该是在限定时间内

点击才会变换后续动作,超过时间就应该播放1,所以你在判断的时候要先判断这个时间.

具体代码自己写写。

float delta;//用于记录上一次点击跟这一次点击的时间间距
void nextAction(int currentAction){
if(delta >= 1){ //如果间距大于1秒
runAction(0);
return;
}
switch(currentAction){
case 0:
runAction(1);
break;
case 1:
runAction(2);
break;
case 2:
runAction(0);
break;
default:
runAction(0)
break;
}
}
不知道你是不是想要实现这种效果

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”);//单击
this->unschedule(schedule_selector(ContButton::updateAttackDelay));
m_pHero->runAttackAction();
touchCounts++;
}
void ContButton::onDoubleClick()
{
CCLOG(“double”); //双击
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;
}
瞬间就写出来了.
感谢,应该是对的。
但总感觉还有能优化的地方

你好,之前我用过你这个算法,但是有问题。途中runAction(2)会打断之前的runAction(1)

这是伪代码,需要自行修改

bool flag; //按下时设为true
Animation * animation;

void update(dt) {//需要在init中启动update
    if (flag) {//当按下按键,进入nextAnimation流程
        nextAnimation();
    } else {//当没有按键并当前动画播放结束,回到待机动画
        if (!animation->isPlaying()) {
            animation->play("待机");
        }
    }
}

void nextAnimation() {//待机,或者动画播放结束时,进入下一个动画
    if (animation->getCurrentMovementID() != "待机" && animation->isPlaying()) {
        return;
    }

    switch (animation->getCurrentMovementID()) {
        case A1:
            animation->play(A2);
            break;
        ……
    }
    flag = false;
}

1.需要A1、A2……为非循环动画,“待机”为循环动画
2.不知道你的蓄力想设计成什么样,没加入蓄力的逻辑

感谢回复。
关于蓄力部分已经完成了,按下按键时取当前动画前几帧,开始定时器
放开按键时候,获取蓄力延时,判断是否为蓄力攻击,然后播放动画,中间回调攻击判断。
简单的demo方法上一楼我贴了,已经解决了,现在在弄稍微复杂点的。
之前弄while 直接卡死整个程序
刚开始接触游戏制作不太好搞。

用帧事件啊