I want to make a new way of handling animations for my game. Currently I detriment object animation states with two variables _physics_State
& _direction_State
used in a switch case and nested switch case respectfully. I want to move away from this method of using switch cases.
switch (_physics_State)
{
case OBJECT_PHYSICS_STATE_GROUNDED:
switch(_direction_State)
{
case OBJECT_DIRECTION_UP: _animation_State = ANIMATION_STATE_YS_IDLE_UP; break;
case OBJECT_DIRECTION_UP_RIGHT: _animation_State = ANIMATION_STATE_YS_IDLE_UP_RIGHT; break;
case OBJECT_DIRECTION_UP_LEFT: _animation_State = ANIMATION_STATE_YS_IDLE_UP_LEFT; break;
case OBJECT_DIRECTION_RIGHT: _animation_State = ANIMATION_STATE_YS_IDLE_RIGHT; break;
case OBJECT_DIRECTION_RIGHT_DOWN: _animation_State = ANIMATION_STATE_YS_IDLE_RIGHT_DOWN; break;
case OBJECT_DIRECTION_DOWN: _animation_State = ANIMATION_STATE_YS_IDLE_DOWN; break;
case OBJECT_DIRECTION_DOWN_LEFT: _animation_State = ANIMATION_STATE_YS_IDLE_DOWN_LEFT; break;
case OBJECT_DIRECTION_LEFT: _animation_State = ANIMATION_STATE_YS_IDLE_LEFT; break;
default: _animation_State = ANIMATION_STATE_YS_IDLE_DOWN; break;
}
break;
}
I have come up with the solution of generating a string by reading variables in a specific order and storing it in a hash map. This seemed to work except with the last variable _speed
. _speed
is continuous not discrete and will likely have a range of values that will still make the object reach the same animation state. I cannot simply store speed as a simple value. How would you handle this continuous data in a way that allow me to search it up with the discrete data?
std::string animation_state_string_results = ""
+ std::to_string(_physics_State)
+ "-" + std::to_string(_direction_State);
+ "-" + std::to_string(G_button_Press_Value);
+ "-" + std::to_string(_speed);