• 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!

Legacy GM Sprite animation when not moving

Y

Yoo

Guest
I'm making a platformer, and I have a sprite animation for Idle and for Moving.

I've used this code for changing between the two:

if hspeed != 0
{
sprite_index = Sprite_Move
image_speed = .6;
}
else
{
sprite_index = Sprite_Idle
}

But, if I hit the wall... an object collision or the edge of the room, the object stops moving, but the Moving sprite is still on as long as I am holding the movement key. How can I make it so that if it's not moving horizontally the sprite is Idle?

Thanx.
 
J

Jordan Robinson

Guest
Make sure you put this code after your collision code, otherwise hspeed will always be != 0 if you are pressing a key, even if you are against a wall. Also make sure you are setting the variable hspeed to 0 in your collision code.
 
  • Like
Reactions: Yoo

Erayd

Member
You could make it dependent on a key press instead of a speed variable. I assume the player is in control of the movement. And while your at it, don't make it directly related to a key press but to a variable that changes based on a key press. That way later you can manipulate that variable in a cut scene for example. Did I help or just go off in some unknown other direction?
 
S

squirrelmonkeycom

Guest
You can also set a variable as soon as the collision starts:
collision=1
And then do this:

if hspeed != 0 and if collision=0
{
sprite_index = Sprite_Move
image_speed = .6;
}
else
{
sprite_index = Sprite_Idle
}
 

Erayd

Member
Wow, just reread the original post and I guess I didn't read it well enough, sorry for that. What squirrel said should work, but also try using specifically wall objects for your walls, so when a collision event is thrown you can set the collision to 0 like squirrel said.
 
M

Misty

Guest
Try replacing your code with
if abs(hspeed)> maxaccelerationstep
{
if sprite_index!=Sprite_Move
sprite_index = Sprite_Move
image_speed = .6;
}
else
{
image_speed = .6;
if sprite_index!=Sprite_Idle
sprite_index = Sprite_Idle
}
This should cover your bases without having to modify your collision system
 
Y

Yoo

Guest
Make sure you put this code after your collision code, otherwise hspeed will always be != 0 if you are pressing a key, even if you are against a wall. Also make sure you are setting the variable hspeed to 0 in your collision code.
I had couple of separate Code sheets, and I haven't placed it right after the collision. And now it works. At least when colliding with objects... It doesn't work for the edge of the screen...

I've used this code so I do not leave the border of the room:

x = min(x,room_width-85);
x = max(x,85);

Once the origin of the sprite is centered 85 is what I get for the X. This code works, object is not leaving the room... just the moving animation thing here as well.
 
J

Jordan Robinson

Guest
It's because you are not setting hspeed to 0. Just readjusting the x position to keep him inside the room. An easier way might be to put a wall object around your room just outside of the view. Then it would collide with those rather than having to calculate if he is outside the room.
 
A

Aura

Guest
I won't suggest sprite handling to be based on a speed variable. I'd rather suggest you to use positioning variables. A simple way to handle sprites would be as easy as this:

Code:
if (!on_ground)
{
   // Aerial sprites
}
else
{
   if (x != xprevious)
   {
      sprite_index = Sprite_Move;
      image_speed = 0.6;
   }
   else
   {
      sprite_index = Sprite_Idle;
   }
}
 
Top