Join Lee Brimelow for an in-depth discussion in this video Creating the IState interface, part of Building Flash Games with Starling.
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.
Starting with installation and configuration of Starling and creation of a Flash Builder project, the course shows how to prepare and import graphical assets, create MovieClip classes from sprite sheets, manage various gaming objects, detect collisions, and add both particle and sound effects. The finished game can be deployed to any browser or mobile device that integrates Flash Player 11, which was released in September 2011.
- Downloading and installing Starling and Flash Builder
- Creating the project
- Creating the main game class, static assets class, and other classes
- Building the state machine
- Creating a static assets class
- Adding images
- Creating sprite sheets with Texture Packer
- Creating and importing bitmap fonts
- Detecting collisions
- Adding particle effects
- Adding sound effects