Watching:

Creating the IState interface


show more Creating the IState interface provides you with in-depth training on Developer. Taught by Lee Brimelow as part of the Building Flash Games with Starling show less
please wait ...

Creating the IState interface

So we are going to be separating our game into different states and more specifically our game is going to have three distinct states. First, it's going to have a Menu state, and this is when you first come into the game it's going to display the logo and a button in which you can start playing the game. Then there's going to be a Play state and this is when you are actually playing the game. And then finally a Game Over state, which will display a message saying, game over and do you want to try and play again. Now a larger scale game of course, you're going to have lots and lots of different possible states.

So to create these state classes what we are first going to do is to create an interface, and an interface is essentially going to require that any state implement a certain set of methods. So I'm going to go to the source folder, right-click and say New > ActionScript Interface, and we are actually going to put this into a package called interfaces. This is the only one we are going to be creating for this game, but still again, it's nice to separate things and organize it into packages. So using the best practices naming conventions, we're going to call it IState, so it's essentially called IState.

I'm going to click Finish. And for our state classes we are going to require that they implement two methods, one is called update and one is called destroy. The update method is going to be called on every frame and that's essentially where we are going to able to update its visuals and do things, different logic operations depending on what state we are in. And then the destroy method is going to handle actually cleaning up after itself, getting rid of the state from memory, so that we don't have memory leaks.

So I'm going to define two functions in here, the first one is called update and the return type of both of these functions is just going to be void, since we are not going to be returning anything from either function. So function destroy(), and again this is going to be of type void for the return type. So that's all we are going to be creating for our interface but now when we create those state classes, when we implement this interface, we'll be sure that each of those states implements the required methods.

Creating the IState interface
Video duration: 2m 14s 2h 57m Intermediate

Viewers:

Creating the IState interface provides you with in-depth training on Developer. Taught by Lee Brimelow as part of the Building Flash Games with Starling

please wait ...