• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML gm:s how to make ladder animation stop or just animation freeze?

O

Otacon Emmerich

Guest
so i have this wrote down
if (on_ladder)
{
ladder = true;
sprite_index = spr_ladder_climb;
if keyboard_check_released(key_up) image_index = yprevious;
if keyboard_check_released(key_down) image_index = yprevious;
}


the animation works fine, but i want it to freeze when i let go of the key but itstead it runs the animation.

also when i add the ladders the keydown is nulifying shaun spauldings oneway platform for me, i can move up through them but not down i noticed this when i wanted to add a invisible oneway platform so i wouldnt fall though, right now i just have set vspd = 0 if obj_player is y+1 obj_ladder for some functionality and it works but i cant jump. havent really looked into yet but if someone can maybe give me a tip with this aswell that would be great.
 

Mazey

Member
Would something like this work:
Code:
if (on_ladder)
{
ladder = true;
sprite_index = spr_ladder_climb;
//When you press up and down at the same moment in your game, do you move or stand still?

//In case you move:
image_speed = sign(keyboard_check(key_up) + keyboard_check(key_down));
}
Explanation:
Set image_speed to 'sign' of 0, 1 or 2. Functions like keyboard_check return a number (0 - false, 1 - true), sign is a function that always returns -1, 0 or 1. If you give sign a number lower than 0, it returns -1, higher than 0 - return 1 and 0 returns 0. This is so when you press both buttons your image_speed doesn't double, but remains 1.
Code:
//In case you do NOT move:
image_speed = (keyboard_check(key_up) + keyboard_check(key_down)) % 2;
}
Explanation:
In case you don't know what modulus is, read about modulo on this page. Basically image_speed is set to 0, 1 or 2%2 -> 0 (so there's no animation when you press both keys)
 
O

Otacon Emmerich

Guest
Would something like this work:
Code:
if (on_ladder)
{
ladder = true;
sprite_index = spr_ladder_climb;
//When you press up and down at the same moment in your game, do you move or stand still?

//In case you move:
image_speed = sign(keyboard_check(key_up) + keyboard_check(key_down));
}
Explanation:
Set image_speed to 'sign' of 0, 1 or 2. Functions like keyboard_check return a number (0 - false, 1 - true), sign is a function that always returns -1, 0 or 1. If you give sign a number lower than 0, it returns -1, higher than 0 - return 1 and 0 returns 0. This is so when you press both buttons your image_speed doesn't double, but remains 1.
Code:
//In case you do NOT move:
image_speed = (keyboard_check(key_up) + keyboard_check(key_down)) % 2;
}
Explanation:
In case you don't know what modulus is, read about modulo on this page. Basically image_speed is set to 0, 1 or 2%2 -> 0 (so there's no animation when you press both keys)
Hmm, thats really cool i could see this working already, thanks for the explanations and i will look further into "modulo" thank you, will post later when i get a chance to test it out.
 
T

The Green Dev

Guest
Thats actually wrong, when you hold down it would actually play the animations forwards instead of backwards, i suggest changing the image_speed line to this
image_speed = (keyboard_check(vk_down)-keyboard_check(vk_up))
 

Mazey

Member
@The Green Dev
I thought you didn't have to play the animation backwards, but if you do, shouldn't it be the other way around? (up - down instead of down - up)
 
Last edited:

Mazey

Member
Yeah but we're not talking about the direction, if you go up shouldn't the climbing animation play (= 1) and if you go down revert it (-1)?
 
O

Otacon Emmerich

Guest
Thats actually wrong, when you hold down it would actually play the animations forwards instead of backwards, i suggest changing the image_speed line to this
image_speed = (keyboard_check(vk_down)-keyboard_check(vk_up))
yes, i did try your original suggestion and it actually speed up all the animations i had, so i will go back and try this later. Thanks again.
 
T

The Green Dev

Guest
yes, i did try your original suggestion and it actually speed up all the animations i had, so i will go back and try this later. Thanks again.
Just multiply it by 0.5 or something depending on your animation
 
O

Otacon Emmerich

Guest
Would something like this work:
Code:
if (on_ladder)
{
ladder = true;
sprite_index = spr_ladder_climb;
//When you press up and down at the same moment in your game, do you move or stand still?

//In case you move:
image_speed = sign(keyboard_check(key_up) + keyboard_check(key_down));
}
Explanation:
Set image_speed to 'sign' of 0, 1 or 2. Functions like keyboard_check return a number (0 - false, 1 - true), sign is a function that always returns -1, 0 or 1. If you give sign a number lower than 0, it returns -1, higher than 0 - return 1 and 0 returns 0. This is so when you press both buttons your image_speed doesn't double, but remains 1.
Code:
//In case you do NOT move:
image_speed = (keyboard_check(key_up) + keyboard_check(key_down)) % 2;
}
Explanation:
In case you don't know what modulus is, read about modulo on this page. Basically image_speed is set to 0, 1 or 2%2 -> 0 (so there's no animation when you press both keys)

thank you, @Mazey and @The Green Dev i didnt seem to notice any difference with - or + expression they both worked equally the same for me?

Code:
///ladder script
var key_uphold = keyboard_check(ord('W'));
var key_downhold = keyboard_check(ord('S'));
var key_jump = keyboard_check(vk_space);
//x =(instance_nearest(x,y,par_ladder).x)
var topladder = place_meeting(x,y,obj_topladder);
var bottonladder = place_meeting(x,y,obj_bottomladder);
//ladder collision code---------------------------------------------------------------------------------------------------
hspd = 0;
vspd = 0;//(key_uphold + key_downhold);
if (key_uphold) vspd = -2;
if (key_downhold) vspd = 2;
x = (instance_nearest(x,y,par_ladder).x);
sprite_index = spr_ladder_climb;
image_speed = sign((key_uphold) - (key_downhold));
image_speed = (key_uphold - key_downhold)/3 ;
     
      if (!on_ladder || key_jump)
            {
            vspd = 0;
            hspd = 0;
            image_speed = .3;
            state = states.normal;
            }
 
O

Otacon Emmerich

Guest
Just multiply it by 0.5 or something depending on your animation
hey thanks for extra advice, i got it working now I was wondering if maybe someone knew how to check right at the top of the obj_ladders very last pixel right before hes !on_ladder, to set the players final climb sprite_index to spr_topladder then once i am finally on top of the ladder y+1 states = states.normal;

a mock code example would be helpful or just the function i would need to go read up on thx
 

Mazey

Member
Something like this? If you're on the ladder and the point above you is not the ladder, set the sprite_index to your spr_topladder image
Code:
if (on_ladder && !position_meeting(x,y-2,obj_topladder))
{
    sprite_index = spr_topladder;
}
 
O

Otacon Emmerich

Guest
Something like this? If you're on the ladder and the point above you is not the ladder, set the sprite_index to your spr_topladder image
Code:
if (on_ladder && !position_meeting(x,y-2,obj_topladder))
{
    sprite_index = spr_topladder;
}
hey thanks again
heres a little more information about
obj_topladdder and obj_bottomladder height is 1 width 32
and players sprite mask height is 32 and width 20ish
ive been trying something like that with your code example
this is how i achieved the look i wanted
Code:
var topladder = place_meeting(x,y+16,obj_topladder);

if (on_ladder && topladder)
{
    sprite_index = spr_ontopladder;
    }

works really well with the key checks handling the image speeds.
may need help with something else with this subject, but im going to try and tackle that myself for now...lol
(also could someone tell me how to post a gif? i used giphy and pasted the embedded link in image)

 
Last edited by a moderator:

phillipPbor

Member
I just got stuck
Code:
//Ladder.....................................................................................
if (KyJ || KyD)
{
    if place_meeting(x,y,par_ladder) ladder = true;
}

if (ladder)
{
    vsp = 0;
    grav = 0;
    if (KyJ) vsp = -2 ;
    if (KyD) vsp = 2 ;
    if !place_meeting(x,y,par_ladder)
    ladder = false; 
  
}
if !(ladder)
grav = 0.3;

//ladder animation............................................................

if (ladder)
{
 image_speed = 0.8;
 sprite_index = any_climb;
}
I used to use this code.
 
L

lol

Guest
I'm literally stuck on this like I want to make image_speed = 0;But instead, it runs the animation!
I'm making a text box, so like when the text is over, the text box closes itself
 
A

Anomaly

Guest
So...

Having a obj_topladder and obj_bottomladder is the way to go it seems.

I've been trying different quicker methods but this seems the best.

Awesome job Otacon!
 
Top