You really need to define simple. The state switch method is simple. All you need to know is how to use a switch statement, and of course a variable. The variable, usually called state, holds what the player is doing (standing, running, etc...). Usually you want to have it include direction.
On an event, keydown right, you use the switch statement.
- Code: Select all
switch(state)
{
case 0: // if standing right
//ChangeAnimation to run
state=2; // run right
break;
case 1: // if standing left
//ChangeAnimation to stand right
state=0; // stand right
break;
case 2: // if running right
// do nothing
break;
case 3: // if running left
// ChangeAnimation to stand left
state=1; // stand left
break;
}
The switch statement breaks up all possible states the player is in. In this example the player can only stand and run. So, if you hold right, you can tell the player exactly what you want it to do, given a certain state. Take case 2 for example. Since case 2 is already running, you don't need the player to do anything. But, if the player is running left (which will mean key left is pressed), the player will stop and face left.
Each event that you want the player to react to should use a switch statement. So, keydown right/left, keyup right/left, collisions with the ground, and so on. Any event that will change the player's animation should have a state.