GMS 2 2-D Platformer Jump Animation Issue

Discussion in 'Programming' started by AngelofGamin, Aug 17, 2019.

  1. AngelofGamin

    AngelofGamin Member

    Joined:
    Aug 17, 2019
    Posts:
    8
    The issue: even if I change the speed values, the jumping animation remains a constant speed. The walking animation I can control just fine.

    [UPDATE: AS IT TURNS OUT, THE PROBLEM IS ENTIRELY DIFFERENT]

    It's not that the animation frame stays a constant speed, I tested a different sprite and as it turns out, it only plays the second frame and leaves out the rest.

    Step code:
    Code:
    // Get input
    key_Left = -keyboard_check(vk_left); key_Right = keyboard_check(vk_right); key_Jump = keyboard_check_pressed(vk_up);
    
    // Use input
    move = key_Left + key_Right; hsp = move * moveSpeed; if (vsp < 10) { vsp += grav; };
    
    if (place_meeting(x, y + 1, obj_jwall)) { vsp = key_Jump * -jumpSpeed }
    
    if (key_Jump) && (place_meeting(x+1,y,obj_jwall) || place_meeting(x-1,y,obj_jwall))
    {
    vsp = key_Jump * -jumpSpeed;
    }
    // H Collisions
    if (place_meeting(x + hsp, y, obj_jwall)) { while (!place_meeting(x + sign(hsp), y, obj_jwall)) { x += sign(hsp); } hsp = 0; } x += hsp;
    
    // v Collisions
    if (place_meeting(x, y + vsp, obj_jwall)) { while (!place_meeting(x, y + sign(vsp), obj_jwall)) { y += sign(vsp); } vsp = 0; } y += vsp;
       
    // Animations
    if (!place_meeting(x,y+1,obj_jwall))
    {
     sprite_index = sp_jplayerjump;
     image_speed = 0;
     if (sign(vsp) > 0) image_index = 1; else image_index = 0;
    }
    else
    {
     image_speed = 1;
     if (hsp == 0)
     {
      sprite_index = sp_jplayer;
     }
     else
     {
      sprite_index = sp_jplayerwalk;
      image_speed = .15;
     }
    }
    
    if (hsp != 0) image_xscale = sign(hsp);
    
     
    Last edited: Aug 17, 2019
  2. Kyrieru

    Kyrieru Member

    Joined:
    Jul 24, 2017
    Posts:
    68
    jump speed is the movement speed

    image_speed is the animation speed, and you have it set to 0 when in the air.
     
  3. AngelofGamin

    AngelofGamin Member

    Joined:
    Aug 17, 2019
    Posts:
    8

    Im aware that its the value of image_speed that I need to change.

    my problem was that even if I change it, it doesn't change the actual speed of the animation
     
  4. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    990
    What is the speed for the sprites sp_jplayer and sp_jplayerwalk?
     
  5. AngelofGamin

    AngelofGamin Member

    Joined:
    Aug 17, 2019
    Posts:
    8
    jplayer is just idle, with no other frames other than the first.

    walk is .15
     
  6. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    990
    If you open the sprite for walk, up the top is where the speed is set. image_speed = 1 will run the sprite at the speed indicated there. I was just wondering if that is set to zero for some reason.

    Note too, if you are changing sprites, you need to ensure you are setting the image_index to 0 as well, otherwise you may skip some frames.
     
  7. AngelofGamin

    AngelofGamin Member

    Joined:
    Aug 17, 2019
    Posts:
    8
    alright I think I got it, I also found out that I needed to change the image_index = 1 for the jumping animation in this part to the actual sprite index


    Code:
    if (!place_meeting(x,y+1,obj_jwall))
    {
     sprite_index = sp_jplayerjump;
     image_speed = 0;
     if (sign(vsp) > 0) image_index = 1; else image_index = 0;
    }
     

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