Code for executing the corresponding animation when the sprite is in an airborne state

⌚Time: 2026-03-13 19:58:00

👨‍💻Author: Jack Ge

These codes are the old codes from before and do not have a separate aloft state. Now I have added a separate aloft state for the game character, so this part of the code is no longer needed. Recording it here.

//Four possibilities: aloft and play aloft animation, aloft and not play aloft animation,not aloft and play aloft animation, not aloft and not play aloft animation

//Correct the two incorrect states
if(is_sprite_aloft()&&!m_animationPlayer.is_playing_aloft_animation()){
    //Play the aloft animation when not in states such as skills, hurt, or death.
    if(strcmp(m_statusMachine.get_current_status_name(),"SkillCasting")
        &&strcmp(m_statusMachine.get_current_status_name(),"Hurt")
        &&strcmp(m_statusMachine.get_current_status_name(),"Fallover")
        &&strcmp(m_statusMachine.get_current_status_name(),"Death")
        &&strcmp(m_statusMachine.get_current_status_name(),"RangedAttack")){
                
        if(get_game_world_object()->speedv>0){
            m_animationPlayer.switch_normal_animation("AloftDown");
        }else{
            m_animationPlayer.switch_normal_animation("AloftUp");
        }
    }
}else if(!is_sprite_aloft()&&m_animationPlayer.is_playing_aloft_animation()){
    //If not in the airborne state, switch to the animation name of the current state
    if(!strcmp(m_statusMachine.get_current_status_name(),"MeleeAttack")){
        m_animationPlayer.switch_melee_attack_animation(m_currentAttackIndex);
    }else if(!strcmp(m_statusMachine.get_current_status_name(),"SkillCasting")){
        m_animationPlayer.switch_skill_animation(m_currentLaunchingSkillName);
    }else{
        m_animationPlayer.switch_normal_animation(m_statusMachine.get_current_status_name());
    }
}
//Dynamic correction of the upper and lower animations in the aloft animation
if(m_animationPlayer.is_playing_aloft_up_animation()&&get_game_world_object()->speedv>0){
    m_animationPlayer.switch_normal_animation("AloftDown");
}
if(m_animationPlayer.is_playing_aloft_down_animation()&&get_game_world_object()->speedv<0){
    m_animationPlayer.switch_normal_animation("AloftUp");
}

Automatically switch to the aloft animation when the state machine enters certain states

virtual void ISpriteStatus_on_status_enter(char *name){
    ...
    //If switching to moving or idle state in air, directly skip the corresponding animation and switch to the airborne animation.
    if((!strcmp(name,"Idle")||!strcmp(name,"Walk"))&&is_sprite_aloft()){
        if(get_game_world_object()->speedv>0){
            m_animationPlayer.switch_normal_animation("AloftDown");
        }else{
            m_animationPlayer.switch_normal_animation("AloftUp");
        }
    }else{
        m_animationPlayer.switch_normal_animation(name);
    }
}