Coding Sword animation swing

Discussion in 'Programming' started by Joao Cruz Malhao, Oct 7, 2018.

  1. Joao Cruz Malhao

    Joao Cruz Malhao Member

    Joined:
    Oct 6, 2018
    Posts:
    13
    Hi, I've been researching (working on an rpg) and found that instead of making hundreds of attack animations would just be easier to animate with code the sword_spr swing. Meaning, just the sword sprite rotating in front of the player's direction during the attack time. How should i approach this, thank you I'm still fairly new to gml. Any tips or help would be much appreciated.
     
  2. Morendral

    Morendral Member

    Joined:
    Jun 27, 2016
    Posts:
    377
    Draw the sprite in the player objects draw event, after the player draw code.
     
  3. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    Well, for the animation you could define a start angle, an end angle and a speed the sword should rotate at. Once you have these, thr code to rotate would be something like this(assuming the weapon is it's own object, and this is put in the step event):

    Code:
    if inSwing {
        if image_angle == endAngle {
            inSwing = false; // animation finished
        }
        image_angle += dsin(endAngle - image_angle) * rotateSpeed;
    }
    
    Then when you want to swing set inSwing = true, and reset image_angle.
     
  4. Joao Cruz Malhao

    Joao Cruz Malhao Member

    Joined:
    Oct 6, 2018
    Posts:
    13
    thank you!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice