Programming a Sequence of Animations

I was wondering about this for a long time now, but how would I program a sequence of animations. I am trying to program a jump animation which has 5 frames( from the time the character is on the ground about to jump to the time she reaches her highest(the last frame).

I know in games like Donkey Kong Country and others, they have at last like 2-5 frames to make the jump animation smoother while in Super Mario( there is one). I was wondering if i should have everything in one gif and program it like that or should I have everything in separate frames.

Here is the code that I been using. It uses only one frame, but I would like to incorporate more frames to the jump.

Code:
// Jump Animation

if vsp < 0
{
sprite_index = spr_jump;
image_speed = .5
}
 
D

Docker

Guest
When I set it when I press the jump key, it doesnt play the jump animation, the character just uses the run animation instead of the jump.
are you trying to do it like:
if jump is pressed
sprite is jump

if left or right
sprite is run

Because that may explain why, the moment left or right is pressed it will change immediately back to the run animation, you probably have that or something similar causing it to happen. This is the code I normally use for detecting jumping:
Code:
if (!place_meeting(x, y+1, par_solid)) {
    sprite_index = jump_sprite;
}
 
are you trying to do it like:
if jump is pressed
sprite is jump

if left or right
sprite is run

Because that may explain why, the moment left or right is pressed it will change immediately back to the run animation, you probably have that or something similar causing it to happen. This is the code I normally use for detecting jumping:
Code:
if (!place_meeting(x, y+1, par_solid)) {
    sprite_index = jump_sprite;
}
oh ok, ill try that out. But what if a jump animation has 2-5 frames in it. That's what I am trying to get to work. How would I set something like that up from frame 1(when he is on the ground) to frame 5(the jump itself)
 

TheouAegis

Member
Well, if you insist on not implementing a proper organized finite state machine, I guess the easiest solution would be

if !place_meeting(x,y+1,par_solid) && sprite_index != jump_sprite
{
sprite_index = jump_sprite;
image_index = 0;
image_speed = 0.5;​
}
 
are you trying to do it like:
if jump is pressed
sprite is jump

if left or right
sprite is run

Because that may explain why, the moment left or right is pressed it will change immediately back to the run animation, you probably have that or something similar causing it to happen. This is the code I normally use for detecting jumping:
Code:
if (!place_meeting(x, y+1, par_solid)) {
    sprite_index = jump_sprite;
}
I just insert the code and it works just as good. thanks a ton and I personally think its a better code to understand. But what i am talking is something like this

https://www.spriters-resource.com/snes/dkc2/sheet/45684/

Before Diddy Kong jump's, he crotches to the ground and then when he jumps, there are are in-between frames before his highest jump. Thats what I want to program.
 
G

Gillen82

Guest
Maybe something similar to this:

Code:
if ( place_meeting (x, y, par_solid ) && jump_key ) {

    //Switch to sprite with crouching animation
    sprite_index = spr_crouching;
    image_speed = 0.2; // or whatever works best

    //Get total sub-images and minus one for last image_index number
    //We are finding the last frame of the animation based on a 5 frame animation
    if ( image_number - 1 == 4) {

        //Switch to jump sprite
        sprite_index = spr_jump;
        image_speed = 0.2;

        //Jump
        Put your jump code here

    }
   

}
 
Last edited by a moderator:
A

Ampersand

Guest
You need to check whether you are in the air or on the ground before you assign animations. Animations honestly ought not ever be assigned by key presses, they should be a combination of physics states and input states.
 
Top