Natural approach to software development

Menu

How to handle states of sprites

Most of sprites in games has states that will change after fires some event.

Simple example:
We have one sprite “Dot”. This sprite has 3 states. Sprite can be clicked, when it will change state. Every state has different texture.

SHOW_EMPTY – empty Dot, sprite will not change it state
SHOW_SELECTED – Dot will be filled, sprite will not change it state
DRAW_EMPTY – Empty dot to change, sprite will change state to DRAW_SELECTED
DRAW_SELECTED- Filled Dot to change, sprite will change state to DRAW_EMPTY

BAD SOLUTION
We will use “if … else” statement and some methods and fields to handle states.