• 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 Jump Up Sprite used as standard Sprite?

U

Ursidae

Guest
Hi,
i'm pretty new to GMS2 and followed a Tutorial on Youtube. Now i'm stuck at changing sprites depending on what the character does. The Tutorial is about 2 Years old and i think they changed how things internally work...
Heres the code:

CREATE
Code:
hsp = 0;
vsp = 0;
grv = 0.1;
walkspd = 4;
STEP
Code:
 //Get Player Input
key_left = keyboard_check (vk_left);
key_right = keyboard_check (vk_right);
key_jump = keyboard_check_pressed (vk_space);

//Calculate Movement
var move = key_right - key_left;

hsp = move * walkspd;

vsp = vsp + grv;

if (place_meeting (x,y+1,oWall)) && (key_jump)
{
    vsp = -7;
}



//Horizontal Collison
if (place_meeting(x+hsp,y,oWall))
{
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
    x = x + sign(hsp);
    }
    hsp = 0;
}

x = x + hsp;

//Vertical Collison
if (place_meeting(x,y+vsp,oWall))
{
    while (!place_meeting(x,y+sign(vsp),oWall))
    {
    y = y + sign(vsp);
    }
    vsp = 0;
}
y = 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;
    
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = sPlayer;
    }
    else
    {
        sprite_index = sPlayerR;
    }
}
Hopefully someone can help =)

Thanks
 

samspade

Member
That looks about right. If the animation is the only thing that doesn't work then the problem might be elsewhere. Have you confirmed that the sprites are correct? What does your draw event look like? Is there any draw code that could be changing or ignoring what you do here?

Also, when you say it doesn't work, how does it not work, are the sprites not changing at all or are they changing in different than expected ways?
 
U

Ursidae

Guest
The character always looks up. It just change the sprite if falling down. What do you mean with draw code?

EDIT: Just read what a draw event is. No i don't got any Draw event in the project.
 
Last edited by a moderator:

samspade

Member
The character always looks up. It just change the sprite if falling down. What do you mean with draw code?

EDIT: Just read what a draw event is. No i don't got any Draw event in the project.
I'm not sure what "The character always looks up. It just change the sprite if falling down" means. Reading your code that sounds like what is supposed to happen, when jumping the character should look up unless falling down. To put it another way, it looks like you should have four different 'animations':
  • idle animation - has multiple frames
  • run right animation - has multiple frames
  • jump up - single frame
  • fall down - single frame
Which of these work do not work and in what circumstances?
 
U

Ursidae

Guest
The only Animation that work is jump up and falling down. If i land on ground the character switches to the jump up frame..

I have an idle frame without any animation.
Run right has an animation
Jump up and down is in an single sprite with 2 Frames
 

samspade

Member
Change this:

Code:
//Animation
if(!place_meeting(x,y-1,oWall))
To this:

Code:
//Animation
if(!place_meeting(x,y+1,oWall))
 
U

Ursidae

Guest
So easy... Thank you so much for the quick answer =D

Now the character moves as expected.
 

samspade

Member
So easy... Thank you so much for the quick answer =D

Now the character moves as expected.
Great. The reason it wasn't working was because you were checking for a collision above the player. Y increases going down and decreases going up. So checking for y-1 looks for a collision one pixel above the player. Notice how your jump code uses y + 1 to check for a collision below the player.
 
Top