Legacy GM I want to code a swinging animation for a guy with a sword.

S

spaceflaffy

Guest
I am new and cannot find the documentation that says how to switch sprites while creating an extended mask representing the weapon being used.
Player01.png Player03.png

The Step event of obj_player01:
Code:
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//React to inputs
move = key_left + key_right;
if (move < 0){
    sprite_index = Player02;
}

if (move > 0){
    sprite_index = Player01;
}

hsp = move * movespeed;
if (vsp < 10) vsp += grav;
 
if (place_meeting(x,y+1,obj_wall))
{
    vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
 

Cerno~b

Member
The easiest way to do sword collision I know of is using a separate object we can call obj_hit. You can give the object an empty sprite or some special effects graphics. Move the object off screen initially by setting its location to x = -1000 or something.

Now during your player's step check if the sprite_index corresponds to your swinging animation and the image_index corresponds to the frames of the animation where you want to connect the blow. If both is true, move obj_hit to where the player is, otherwise move it back to x = -1000. Whenever an opponent collides with obj_hit, deal some damage.
 
Top