When to switch to hero_idle animation?

Started by
14 comments, last by Alberth 8 years, 1 month ago

Guys, I spent whole day trying to find a solution to this. I don't know how to say to the game to show the Ryu's IDLE animation. The only thing that comes to mind is: If no key is pressed, show_ryu_idle(), so I need to check all the possible buttons on my keyboard every single frame, but I'm sure there is more elegant solution, but nothing comes to mind. I tried to to do it like this: if ( no other animation is currently been shown ) { set anim to idle }, but the problem is that the SDL_KEYDOWN doesnt work that way. For example if I press UP ARROW, and i hold the up arrow for 120 frames, it will count as the key was down only once. So if I set the animation when the key is pressed, it will only work for the 1st frame... If you understood something from this, tell me how you made your own games to handle this??

Advertisement

Afaik, SDL sends you "key pressed down" and "key released" events, ie it detects changes between on and off only.

If you want the current state of a button, you need to store the last event for that button, like

boolean button = false;

if (key_down) buton = true;

if (key_up) button = false;

and in your idle animation: if (!button) ....

ok, i got it

So, I need to declare variables for all the buttons, and check every frame if they are false???( so i can make the IDLE anim)

If you want the idle animation when the user has nothing pressed, yes

You should probably keep the details of that logic eg in the user input somewhere, and compute "isIdle" there, which you can use in the remainder of the game.

One step further you can hide all key details that way. If you ever want to allow changing the used keys, that would be a simple local change.

You can also merge all those functions into one


enum KeyDirection {
  KD_NONE, // or KD_IDLE
  KD_LEFT,
  KD_RIGHT,
  KD_UP,
  KD_DOWN,
};
  
KeyDirection getDirection(); // in the keyboard handler.

i use getAsyncKeyState to get similar keyboard info from the winAPI.

all input is processed immediately, not deferred for later processing.

once input is processed, i then figure out which animation to play, based on the input.

so yes, i check all the keys, then determine the animation.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

I think it would be better to set a player action state depending on the player's position of action. This is because the way you describe, if the player attacked, and didn't press anything since pressing the attack button, no key would be pressed, or if the character would be falling.

For example: A player would have one action state set at a time, and you could select an animation depending on this. Idle animation could be played if the speed is == 0, and if they player is not currently in the process of another state such as falling or attacking.

~GTE

An action state could in itself have a few states, such as if it is complete, or if it is still in the process, and it's priority. The priority would determine whether or not it would or could be cancelled. Such as an idle state, which could be cancelled by walking or falling.

~GTE

I can't make it. Animations are totally messed up. Is there some tutorial or book or something? I need some pseudocode...

Can you show us what you have so far?

~GTE

This topic is closed to new replies.

Advertisement