Create a startup animation before jumping?

Discussion in 'Programming' started by clyver, Jan 3, 2019.

  1. clyver

    clyver Member

    Joined:
    Dec 2, 2017
    Posts:
    11
    I learned how to use a frame to jump and a frame to fall with Shaul Spalding's tutorial but i couldn't realize how i use a startup animation before the player jump. I want to use a quick 4-frames 15-fps animation before the player jump, and how can I do that?

    Code:
    //Get Player Input
    key_left = keyboard_check(vk_left);
    key_right = keyboard_check(vk_right);
    key_jump = keyboard_check_pressed(vk_up);
    key_down = keyboard_check_pressed(vk_down);
    
    
    
    
    //Calculate Movement
    var move = key_right - key_left;
    
    hsp = move * walksp;
    
    vsp += grv;
    
    
    if (key_jump)
    {
        jumptimes+=2;
    }
    
    
    if (jumptimes = 0)
    jumptimes++;
    
    if (place_meeting(x,y+1,oWall))
    jumptimes = 0;
    
    if ((place_meeting(x,y+1,oWall)) && (key_jump))
    {   
        sprite_index = sPlayerJ;
            vsp = -7;
    }
    
    if ((!place_meeting(x,y+1,oWall)) && (key_jump) && vsp>0)
    {
        vsp = -9;
        vsp += jumptimes;
    }
    
    if (!place_meeting(x,y+1,oWall)) && (key_down)
    {
        vsp += 4;
    }
    
    if (!place_meeting(x,y+1,oWall)) && (key_down)
    {
        vsp += 4;
    }
    
    
    
    
    
    
    //Horizontal Collision
    if (place_meeting(x+hsp,y,oWall))
    {
        while (!place_meeting(x+sign(hsp),y,oWall))
        {
             x += sign(hsp);
        }
        hsp = 0;
        
    }
    x += hsp;
    
    
    //Vertical Collision
    if (place_meeting(x,y+vsp,oWall))
    {
        while (!place_meeting(x,y+sign(vsp),oWall))
        {
             y += sign(vsp);
        }
        vsp = 0;
        
    }
    y += vsp;
    
    //Animation
    if (!place_meeting(x,y+1,oWall))
    {
        sprite_index  = sPlayerA;
        image_speed = 0;
        if (sign(vsp) > 0) image_index = 1; else image_index = 0;
        //Se a velocidade vertical for positiva,
        //está pulando, se não, está caindo
    }
    else
    {
        image_speed = 1;
        if (hsp == 0)
        sprite_index = sPlayer;
        else
        sprite_index = sPlayerR;
    }
    
    if (hsp != 0 ) image_xscale = sign(hsp);
     
  2. Becon

    Becon Member

    Joined:
    Jul 13, 2016
    Posts:
    109
    For me I would pretend that 4 frame start up was the jump animation but wouldn't make it jump unless it was on the last frame. If it was...then I would make him jump and change to the next animation...the jump animation.
    Something like this:
    Code:
    If key_jump
     {
      play your wind up animation.
      if image_index >=3  //if it's on the last frame of your wind up
      {
      Play your jump animation and jump
      }
     }
    Let me know if this helps!!!
     
  3. clyver

    clyver Member

    Joined:
    Dec 2, 2017
    Posts:
    11
    i tried it, but i dont know what to do since the animation cant happen if the player is still in the ground
    Code:
    if ((place_meeting(x,y+1,oWall)) && (key_jump))
    //no chão e pula
    {
    
        sprite_index = sPlayerStartup;
        image_speed = 1.5;
    }
    
        if ((sprite_index = sPlayerStartup) and (image_index > 3))
        vsp = -7;
    
    if (!place_meeting(x,y+1,oWall))
    //não tá no chão
    {
        sprite_index  = sPlayerA;
        image_speed = 0;
        if (sign(vsp) > 0) image_index = 1; else image_index = 0;
        //Se a velocidade vertical for positiva,
        //está pulando, se não, está caindo
    }
    
    
    if ((place_meeting(x,y+1,oWall)))
    //no chão
    {
        image_speed = 1;
        if (hsp == 0)
        sprite_index = sPlayer;
        else
        sprite_index = sPlayerR;
    }
    also, if i remove the last part, the player does what i want, but i cant remove it
     

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