GM:S 1.4 How to perform attack animation while holding left mouse button?

Discussion in 'Programming' started by mrjonwc, Mar 17, 2019.

  1. mrjonwc

    mrjonwc Member

    Joined:
    Aug 3, 2016
    Posts:
    68
    I want to perform a continued attack animation when holding down the left mouse button.

    I figured I can set an alarm on if mouse check but this isn’t working.
     
  2. VagrantWhaleGames

    VagrantWhaleGames Member

    Joined:
    Jul 10, 2018
    Posts:
    58
    Use a state machine to control when and what animation to play.

    Code:
    if(mouse_check_button(mb_left))
    {
    state="attack"
    }
    else
    {
    state="idle"
    }
    
    switch(state)
    {
    case "idle":
    sprite_index=sprPlayerIdle;
    break;
    case "attack":
    sprite_index=sprPlayerAttack;
    break;
    }
     
    Last edited: Mar 17, 2019
  3. Sk8dududu

    Sk8dududu Member

    Joined:
    Aug 14, 2017
    Posts:
    141
    A lot less work to just not use switch for a couple of actions.
    But the basic idea is there, the "mouse_check_button(mb_left)" function just checks if you are currently holding your mouse button down. And then you can give it an action..
    Step event
    Code:
    if mouse_check_button(mb_left)
    {
    Sprite_index=spr_atk;
    }
    else
    {
    Sprite_index = spr_idle;
    }
     

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