SOLVED Need help about managing sub images in one sprite sheet (animation)

G#m_Player2

Member
Hello GameMaker Community this is my first time using the forum and I don't have much knowledge in programming but as a starter I am willing to open for learning and understand the basics of gamemaker language.

As a starter, I wanted to make a platformer game and I followed tutorials on youtube specifically Shaun Spalding's platformer tutorial series. As I follow the tutorial series I realized that I can't move forward to episode 3 because I have a certain problem in episode 2 (animation). Link:

The video talks about how to program walking animation and jumping animation.
My problem in episode 2 is the Jumping animation where Shaun shows one sprite sheet containing 2 sub-images each of them used in different situations. 1 sub-image going up and another down.

What I personally wanted was to make 2 sub-images animate while ascending from ground instead of 1 and animate another 2 sub-images while descending from above. All containing 4 sub-images in one sprite sheet instead of 2 sub-images in 1 sprite sheet that Shaun was using.

I hope someone can understand this and help me :)
This would really put a big progress for me as a starter. Thank you.
 

Yal

🐧 *penguin noises*
GMC Elder
  • Use a counter variable walkimage which you add to every step. (Pick a value that works for the speed of your animation)
  • When setting the image when jumping, set subimage 0 + (walkimage mod 2) for when moving up, 2 + (walkimage mod 2) when moving down.
 

Felbar

Member
the other thing you could do is split it into 2 - 2 frame animations air_up and air_down lets say
and set your animation based on your vertical speed so
Code:
if(  in air  )  {

sprite_index = (vspd < 0 ? air_up : air_down);

}
 

G#m_Player2

Member
  • Use a counter variable walkimage which you add to every step. (Pick a value that works for the speed of your animation)
  • When setting the image when jumping, set subimage 0 + (walkimage mod 2) for when moving up, 2 + (walkimage mod 2) when moving down.
the other thing you could do is split it into 2 - 2 frame animations air_up and air_down lets say
and set your animation based on your vertical speed so
Code:
if(  in air  )  {

sprite_index = (vspd < 0 ? air_up : air_down);

}
Thanks for the help guys but how exactly should I put it though? 😕
This is what I made using Shaun Spalding's code for jumping.
GML:
if (!place_meeting(x,y+1,oWall))
{
    sprite_index = sPlayer_jump;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 2; else image_index = 0;
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = sPlayer;
    }
    else
    {
        sprite_index = sPlayer_run;
    }
}
 

Felbar

Member
I would do something like this
with the animation split into air up and air down animations

GML:
if (!place_meeting(x,y+1,oWall)) // if falling
{
  
    //make sprite face proper direction
    if (hsp !=0) image_xscale = sign(hsp);

    //if falling down
    if (sign(vsp) > 0) {
        image_speed = 1;// or w/e your image speed is for this animation

        //check if we are not already on this animation
        if( sprite_index != sAirDownAnimation ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sAirDownAnimation;
            image_index = 0;
        }
    }
    //falling up, lol
    else {
        image_speed = 1;// or w/e your image speed is for this animation
        //check if we are not already on this animation
        if( sprite_index != sAirUpAnimation ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sAirUpAnimation;
            image_index = 0;
        }
    }
}
else // on ground
{
    //if not moving left or right
    if (hsp == 0)
    {
        //set image speed for this animation
        image_speed = 1;
        //check if we are not already on this animation
        if( sprite_index != sPlayer ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sPlayer;
            image_index = 0;
        }
    }
    else // we are moving left or right
    {
        //set image speed for this animation
        image_speed = 1;
        //make sprite face proper direction
        image_xscale = sign(hsp);
        //check if we are not already on this animation
        if( sprite_index != sPlayer_run) {
            //we are not so set it and reset animation to first frame
            sprite_index = sPlayer_run;
            image_index = 0;
        }
    }
}
 
Last edited:

G#m_Player2

Member
I would do something like this
with the animation split into air up and air down animations

GML:
if (!place_meeting(x,y+1,oWall)) // if falling
{
 
    //make sprite face proper direction
    if (hsp !=0) image_xscale = sign(hsp);

    //if falling down
    if (sign(vsp) > 0) {
        image_speed = 1;// or w/e your image speed is for this animation

        //check if we are not already on this animation
        if( sprite_index != sAirDownAnimation ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sAirDownAnimation;
            image_index = 0;
        }
    }
    //falling up, lol
    else {
        image_speed = 1;// or w/e your image speed is for this animation
        //check if we are not already on this animation
        if( sprite_index != sAirUpAnimation ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sAirUpAnimation;
            image_index = 0;
        }
    }
}
else // on ground
{
    //if not moving left or right
    if (hsp == 0)
    {
        //set image speed for this animation
        image_speed = 1;
        //check if we are not already on this animation
        if( sprite_index != sPlayer ) {
            //we are not so set it and reset animation to first frame
            sprite_index = sPlayer;
            image_index = 0;
        }
    }
    else // we are moving left or right
    {
        //set image speed for this animation

        //make sprite face proper direction
        image_xscale = sign(hsp);
        //check if we are not already on this animation
        if( sprite_index != sPlayer_run) {
            //we are not so set it and reset animation to first frame
            sprite_index = sPlayer_run;
            image_index = 0;
        }
    }
}
Woahhhh dude this really helped alot I tried spliting the sprite into two and use your line of code and gladly it really helped alot. Thanks man! I really appreciated your help :banana:
 
Top