Create a startup animation before jumping?

C

clyver

Guest
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);
 
B

Becon

Guest
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!!!
 
C

clyver

Guest
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!!!
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
 
Top