From the course: Building Flash Games with Starling

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Building the state machine

Building the state machine

From the course: Building Flash Games with Starling

Start my 1-month free trial

Building the state machine

Okay, so now we have our three main game states created. Now our main Game class is going to actually incorporate a state machine and its whole purpose is going to be to switch between the various states of our game. So with the top of Game class, I am going to define three constants which are actually going to represent each of the states in the state machine. So I am going to say public, and these are going to be static so that we can reference them anywhere and they are going to be directly attached to our class, and we are going to say const for constant, and the first one is going to be MENU_STATE and these are going to be simple integer values, and they just have to contain unique integer values. I am going to set this one equal to zero. I am going to duplicate that twice and now we are going to change this to PLAY_STATE and I am going to make this one a value of 1. We'll make this one a value of 2 and change it to GAME_OVER_STATE, like that. So again, just these three constants…

Contents