A
Anorak21
Guest
Hi everyone, I recently started making a two-player sword fighting game, and as I was coding the attack animations I came across a couple of problems. If I started the game and immediately pressed the attack button, the animation worked perfectly and didn't loop. However, if I ran around the stage and pressed the attack button while running, the animation would loop forever. If I ran around for a bit, stopped until the player's speed reaches 0, and then pressed the attack button, the animation would play out, but very slowly. It would move at about a frame per 2 seconds. I do not know how to fix this and any help would be appreciated. Most of my code for attacking is from Shaun Spalding's melee attacking tutorial on youtube. I use a state machine for my character, and here is the code for the attacking state:
The scr_AnimationEnd mentioned at the bottom is a bit of script from the gamemaker discord that helps end the animation correctly. Here it is:
Now I don't know if there's something wrong with the animation end script or my code, but I really don't know what to do. I've tried many things, and none of them seem to work. Any help would be appreciated because I'm getting pretty desperate.
Thanks in advance!
GML:
xSpeed = 0
ySpeed = 0
//Start of the attack
if (sprite_index != sPlayerOneAttack)
{
sprite_index = sPlayerOneAttack;
image_index = 0;
ds_list_clear(hitByAttack);
}
//Use attack hitbox & check for hits
mask_index = sPlayerOneAttackHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x, y, oPlayerTwo, hitByAttackNow, false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
//If this instance has not yet been hit by this attack
var hitID = hitByAttackNow[| i];
if (ds_list_find_index(hitByAttack, hitID) == -1)
{
ds_list_add(hitByAttack, hitID);
with (hitID)
{
instance_destroy(oPlayerTwo);
}
}
}
}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayerOneIdle;
if (scr_AnimationEnd())
{
playerOneVertState = verticalstate.onGround;
sprite_index = sPlayerOneIdle;
}
Code:
var _sprite=sprite_index;
var _image=image_index;
if(argument_count > 0) _sprite=argument[0];
if(argument_count > 1) _image=argument[1];
var _type=sprite_get_speed_type(sprite_index);
var _spd=sprite_get_speed(sprite_index)*image_speed;
if(_type == spritespeed_framespersecond)
_spd = _spd/room_speed;
if(argument_count > 2) _spd=argument[2];
return _image+_spd >= sprite_get_number(_sprite);
Thanks in advance!