M
maranpis
Guest
Hello guys:
As you can see in the video if the enemy changes the state from attacking to chasing the attack animation doesn't finish and is been switched inmediately by the running animation.
This happens because the attack animation has two tracks: track 0 (running animation) and track 1 (attacking animation) when I use the animation ends event it refers to running animation. So I don't know how to code " when the attacking animation has finished and the enemy is in the green circle(chase state) then you can switch the animation to running"
STEP EVENT:
ANIMATION END EVENT:
// This code works for changing between when the enemy lift the sword the sword to when the enemy keep running with the sword.
I have read the documentation and i know there is this code: skeleton_animation_get_duration(animname);
But I don't understand the examples given:
Any idea of how to get the track 1 duration?
thanks guys!
As you can see in the video if the enemy changes the state from attacking to chasing the attack animation doesn't finish and is been switched inmediately by the running animation.
This happens because the attack animation has two tracks: track 0 (running animation) and track 1 (attacking animation) when I use the animation ends event it refers to running animation. So I don't know how to code " when the attacking animation has finished and the enemy is in the green circle(chase state) then you can switch the animation to running"
STEP EVENT:
switch (Estate) {
case "enemy_idle" :
#region IDLE STATE
////**************** SETTING VARIABLES********************************////
var EPdist= point_distance(x,y,o_player.x,o_player.y);
////**************** CONDITIONS IN ORDER TO CHANGE TO OTHER STATES********************////
if (EPdist>view_range){ (green circle in the video)
if ( skeleton_animation_get() !=EAidle) { // set animation to idle
image_speed= 1; // normal speed
skeleton_animation_set(EAidle);
}
} else if ( EPdist <= view_range and EPdist >attack_range) { // set to chase
Estate_text= "CHASE";
Estate= "enemy_chase";
if ( skeleton_animation_get() !=EArun) { // chase animation
image_speed=5;
skeleton_animation_clear(1);
skeleton_animation_set(EArun);
}
}
break;
#endregion
case "enemy_chase" :
#region ENEMY CHASE
EB_idle=false // states for animation
EB_chase=true;
EB_attack=false;
var EPdist= point_distance(x,y,o_player.x,o_player.y);
Estate_text= "CHASE"; // change the state text to chase
if (EPdist >attack_range and EPdist<= view_range) {// move and chase
// movement
x+= ehs*sign(o_player.x-x);
// add horizontal speed to and multiply by 1 or -1 depending the players position
skeleton_animation_clear(1);
// skeleton animation clear works here
} else if ( EPdist<= attack_range) {// from chase to attack
Estate= "enemy_attack";
image_speed=5;
skeleton_animation_set_ext(EAattack,1); // mix two animations with tracks
skeleton_animation_set(EArun);
if (skeleton_animation_get()==EArun){
}
} else { // go back to idle
skeleton_animation_clear(1);
Estate= "enemy_idle";
}
// Scale enemy change
if ( sign(o_player.x -x) ==-1 ) {
image_xscale=1;
} else { image_xscale=-1}
break;
#endregion
case "enemy_attack" :
#region ENEMY ATTACK
var EPdist= point_distance(x,y,o_player.x,o_player.y);
Estate_text="ATTACK" // change state text
CONDITIONS****************************************///
if (EPdist>attack_range and EPdist <= view_range) {// from attack to chase
Estate="enemy_chase";
if ( skeleton_animation_get() !=EArun) { //change to run
image_speed=8;
skeleton_animation_set(EArun);
}
}
}
break;
#endregion
}
case "enemy_idle" :
#region IDLE STATE
////**************** SETTING VARIABLES********************************////
var EPdist= point_distance(x,y,o_player.x,o_player.y);
////**************** CONDITIONS IN ORDER TO CHANGE TO OTHER STATES********************////
if (EPdist>view_range){ (green circle in the video)
if ( skeleton_animation_get() !=EAidle) { // set animation to idle
image_speed= 1; // normal speed
skeleton_animation_set(EAidle);
}
} else if ( EPdist <= view_range and EPdist >attack_range) { // set to chase
Estate_text= "CHASE";
Estate= "enemy_chase";
if ( skeleton_animation_get() !=EArun) { // chase animation
image_speed=5;
skeleton_animation_clear(1);
skeleton_animation_set(EArun);
}
}
break;
#endregion
case "enemy_chase" :
#region ENEMY CHASE
EB_idle=false // states for animation
EB_chase=true;
EB_attack=false;
var EPdist= point_distance(x,y,o_player.x,o_player.y);
Estate_text= "CHASE"; // change the state text to chase
if (EPdist >attack_range and EPdist<= view_range) {// move and chase
// movement
x+= ehs*sign(o_player.x-x);
// add horizontal speed to and multiply by 1 or -1 depending the players position
skeleton_animation_clear(1);
// skeleton animation clear works here
} else if ( EPdist<= attack_range) {// from chase to attack
Estate= "enemy_attack";
image_speed=5;
skeleton_animation_set_ext(EAattack,1); // mix two animations with tracks
skeleton_animation_set(EArun);
if (skeleton_animation_get()==EArun){
}
} else { // go back to idle
skeleton_animation_clear(1);
Estate= "enemy_idle";
}
// Scale enemy change
if ( sign(o_player.x -x) ==-1 ) {
image_xscale=1;
} else { image_xscale=-1}
break;
#endregion
case "enemy_attack" :
#region ENEMY ATTACK
var EPdist= point_distance(x,y,o_player.x,o_player.y);
Estate_text="ATTACK" // change state text
CONDITIONS****************************************///
if (EPdist>attack_range and EPdist <= view_range) {// from attack to chase
Estate="enemy_chase";
if ( skeleton_animation_get() !=EArun) { //change to run
image_speed=8;
skeleton_animation_set(EArun);
}
}
}
break;
#endregion
}
ANIMATION END EVENT:
Code:
if (skeleton_animation_get()== EArun) {
image_speed=4;
skeleton_animation_set(EAupsw);
}
I have read the documentation and i know there is this code: skeleton_animation_get_duration(animname);
But I don't understand the examples given:
Example1:
time += delta_time / 1000000;
var duration = skeleton_animation_get_duration(skeleton_animation_get());
var frame = floor((image_number * (mTime / duration)) + 0.5) % image_number;
image_index = frame;
draw_self();
The above code will set the image_index to the correct value for the currently assigned skeletal animation sprite.
Example2:
time += delta_time / 1000000;
var d = skeleton_animation_get_duration("walk");
if time > d time -= d;
draw_skeleton_time(sprite_index, "walk", "skin1", time, x, y, image_xscale, image_yscale, image_angle, c_white);
The above code will draw the given skeletal animation sprite using delta-time to set the frame being drawn.
time += delta_time / 1000000;
var duration = skeleton_animation_get_duration(skeleton_animation_get());
var frame = floor((image_number * (mTime / duration)) + 0.5) % image_number;
image_index = frame;
draw_self();
The above code will set the image_index to the correct value for the currently assigned skeletal animation sprite.
Example2:
time += delta_time / 1000000;
var d = skeleton_animation_get_duration("walk");
if time > d time -= d;
draw_skeleton_time(sprite_index, "walk", "skin1", time, x, y, image_xscale, image_yscale, image_angle, c_white);
The above code will draw the given skeletal animation sprite using delta-time to set the frame being drawn.
Any idea of how to get the track 1 duration?
thanks guys!