Need Help with setting up a Jump action for Character!

P

Pot

Guest
So I have basic code that allows my character to jump, that's nice and all but I need something more.
I want to add an anticipation action before the actual jump for my character after the jump button is pressed.

So the plan is to have the anticipation animation which is crouching on the spot and preparing to jump for like x seconds before the jump.

I Imagine to be easier to use hold down button to jump kind of system where holding down the button makes you crouch and letting go lets you jump.

It will be nice if someone can tell me both method
1. The press button to initiate anticipation crouch and to jump automatically setup
2. The Hold down button to crouch and let go to jump setup

I am super new to coding, so whatever help I can get I will be super happy.

P.S currently I have the anticipation and jump actions in a single animation sequence for the gif of my character.
 

DarthTenebris

Definitely not a Sith Lord
I would use several sprites. 1 for crouching, 1 for jumping, and 1 normal sprite.

This is to control jumping:
Code:
if (keyboard_check(jump_button)) {
     action = "crouch";
}
if (keyboard_check_released(jump_button)) {
     action = "jump";
     jump_action(); //jump code
}
This is to handle animations:
Code:
switch(action) {
     case "crouch": {
          sprite_index = crouch_sprite;
     } break;
     case "jump": {
          sprite_index = jump_sprite;
          alarm[0] = some_time_measured_in_steps;
     } break;
     default: {
          sprite_index = normal_sprite;
     }
}
Put this in alarm[0] event:
Code:
sprite_index = normal_sprite;
Haven't tested, but should work. Don't copy-paste, use your brain and try to figure out which part of the code does what.
As for the sprite, for my code to work, you would have to disassemble your gif image and turn it into several parts of the animation. (a .gif formatted image still works, but the point is, you need multiple pieces of the image separated into a normal image, a crouching image, and a jumping image.)
 
P

Pot

Guest
Thanks for the Reply!
I am trying learn coding so I will definitely do my best not to copy paste. Especially with the variables.

Speaking of variables, how will the animation be implemented for them? Do I define the actions as the respective action sequences as custom variables?
Something like Jump=sprite_index (random_sprite, 0,1,2,3) ?

Yes, I am complete beginner and my English is not professional level I so sorry!!!

P.S I find your words trustworthy but that profile picture has an opposite effect...but don't worry about that!
 
P

Pot

Guest
This happened
was I supposed to define action in create?
___________________________________________
ERROR in
action number 1
of Step Event
for object obj_player2:
Error in code at line 44:
switch(action){
^
at position 9: Unknown variable action
 
Top