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

Animating an Idle Object

S

SmallyBiggs

Guest
Hi,

This would seem to be a very basic and common problem, but I've not been able to find anything referring to this specific issue.

I'm using the 'key_press events" to move my Player object with the arrow keys, and also to change sprites accordingly. I also have an animated "Idle Player" sprite that I'd like the Player object to change into and stop moving when none of the arrow keys are pressed. I tried using the keyboard event "no key pressed", but it doesn't play the Idle Player animation. Instead, it stops at the first frame. I assume this is because the player object is constantly changing into the the idle sprite if no key is pressed, but I'm not exactly sure. Also I should note that when I press any other key besides the arrow keys, it DOES play through the idle animation. :confused:

I'm using drag & drop functions, but I'm also familiar with basic code. Any help is greatly appreciated.

Thank You,
Benny

movement.png
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
If you think constantly changing to the idle sprite is the problem, check that it isn't already the idle sprite before setting it.
 
S

SmallyBiggs

Guest
If you think constantly changing to the idle sprite is the problem, check that it isn't already the idle sprite before setting it.
The Idle Sprite is actually set as the Player object's default sprite, I'm not sure if that's what you meant. I currently have it set to stop moving and change back into the idle sprite whenever no key is pressed. That seemed like the most straightforward and logical way, but it doesn't seem work for what I'm attempting.
 

Tthecreator

Your Creator!
what FrostyCat is trying to say is you whould use something like the following code:
//inside no key event
image_index=spr_idle

But my guess is that you are using drag and drop? and using the change sprite funciton. since changing image_index shouldn't affect image_number.
Anyways, i would also recommend checking for only the arrow keys to be not pressed, else the idle animation will not start when i'm randomly pressing the 'r' key for example.

Consider using some CODE(yes, scary) like this:
Code:
//we are using an if statement, saying that IF some statement is true, THEN execute some code between "{ }".
//The ! means not, because we are checking if the keys are NOT pressed.

if !(keyboard_check(vk_up) or keyboard_check(vk_down) or keyboard_check(vk_left) or keyboard_check(vk_right))then{
//the image_index variable says what sprite we are using.
//image_number whould mean what image inside the sprite we are using, but since we don't need that, we won't set it.
image_index=spr_idle
}
 
S

SmallyBiggs

Guest
what FrostyCat is trying to say is you whould use something like the following code:
//inside no key event
image_index=spr_idle

But my guess is that you are using drag and drop? and using the change sprite funciton. since changing image_index shouldn't affect image_number.
Anyways, i would also recommend checking for only the arrow keys to be not pressed, else the idle animation will not start when i'm randomly pressing the 'r' key for example.

Consider using some CODE(yes, scary) like this:
Code:
//we are using an if statement, saying that IF some statement is true, THEN execute some code between "{ }".
//The ! means not, because we are checking if the keys are NOT pressed.

if !(keyboard_check(vk_up) or keyboard_check(vk_down) or keyboard_check(vk_left) or keyboard_check(vk_right))then{
//the image_index variable says what sprite we are using.
//image_number whould mean what image inside the sprite we are using, but since we don't need that, we won't set it.
image_index=spr_idle
}
Thank you. I am using drag and drop functions, but I am fairly familiar with basic code. This is beginning to make more sense. However I'm still confused about where/ when this check should take place. My initial thought was to have it perform this check in its step event, so that it would constantly check to see if these keys are not pressed, but that didn't work.
 
S

SmallyBiggs

Guest
I've attached an image to better explain my current setup:

It seems like it should work quite simply, but I'm not sure what's preventing the animation from playing.
The movement speed for all directions is 4 (and stopped when "no key pressed"), if that is at all relevant.
 

Attachments

A

anomalous

Guest
Your" no key pressed" changes the sprite to idle every step.
change sprite includes a setting for the subimage, which defaults to 0.
You were correct in that you are continually setting it.

The suggestion was to check if its already set to the idle sprite, and only if it is NOT, change it to idle sprite. This may require code, I have no idea about D&D.
If you know how to check your sprite index in D&D do that, or maybe find out about how to do that. What is "test expression"? Can you test sprite_index != spr_playerIdle using that?
if so, do that, and if true, set it (and if not, it won't do anything).
 
S

SmallyBiggs

Guest
Thank You for clearing that up, I misinterpreted the original suggestion. It doesn't seem to be possible with D&D, but it seems simple enough to work out in code using that approach. I'll continue to experiment with it. Thank you both! Any input is sill welcomed!
 
Last edited by a moderator:
S

SmallyBiggs

Guest
If you think constantly changing to the idle sprite is the problem, check that it isn't already the idle sprite before setting it.
Your" no key pressed" changes the sprite to idle every step.
change sprite includes a setting for the subimage, which defaults to 0.
You were correct in that you are continually setting it.

The suggestion was to check if its already set to the idle sprite, and only if it is NOT, change it to idle sprite. This may require code, I have no idea about D&D.
If you know how to check your sprite index in D&D do that, or maybe find out about how to do that. What is "test expression"? Can you test sprite_index != spr_playerIdle using that?
if so, do that, and if true, set it (and if not, it won't do anything).
Thank you for clearing that up. As far as I can tell, this doesn't seem possible with d&d, but it seems simple enough to work out in code. I'll continue to experiment with it. Thank you Both! Any input is still welcomed!
 
Top