Okay, I think I understand the jump glitch (although I'm only right if your jump animation is only 1 or 2 frames long).
Code:
//sprite control
if (hsp != 0) image_xscale = move*orig_scale;
if (place_meeting(x, y+1, obj_platform))
{
if (move!=0) sprite_index = spr_player_running; else sprite_index = spr_player_idle;
}
else
{
if (vsp !=0) sprite_index = spr_jump;
}
if(punch == 1 || punchanimation = true)
{
punchanimation = true;
if(punch == 1) image_index = 0;
if(image_index >= image_number - 1)
{
punchanimation = false;
punch = 0
}
else sprite_index = spr_player_punch;
}
So what we have happening is this:
First step
1) In the first half of the sprite control, the sprite is set to spr_player_jump. Therefore image_number is set to the number of frames in the jump sprite.
2) In the second half of the sprite control, we've determined we're in a punch, set image_index to 0 and punchAnimation to true. The sprite is changed to spr_player_punch. image_number is now set to 7 (or however many frames you have).
3) At the end of this step, image_index is incremented to 1 by GMS.
Second step
1) In the first half of the sprite control, the sprite is once again set to spr_player_jump. image_number is set back to the number of frames in the jump sprite (which I'm assuming is 1 or 2).
2) Again we determine we're in a punch, but because this step the punch key isn't pressed, image_index is not reset to 0. So image_index (1) > image_number (1) - 1. So it assumes the punch animation is over, and doesn't reassign the sprite.
If I'm right, there is 3 easy ways to fix it.
1) Change the order of code so that the correct image is set before performing this check.
2) Hardcoding the number of frames into this check.
3) Using sprite_get_number(spr_player_punch) in place of image_number.
I think option 1 is probably the most elegant.
Code:
//sprite control
// Turn sprite first
if(hsp != 0) image_xscale = move * orig_scale;
// Now check if punching
if(punch == 1 || punchanimation == true)
{
punchanimation = true;
if(punch == 1) image_index = 0;
if(image_index >= image_number -1) punchanimation = false;
else sprite_index = spr_player_punch;
}
else if (place_meeting(x, y+1, obj_platform)) // Not punching, check if on ground
{
if (move!=0) sprite_index = spr_player_running; else sprite_index = spr_player_idle;
}
else // Not on ground
{
if (vsp !=0) sprite_index = spr_jump;
}