Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98529 Viewers
61 Video lessons · 85819 Viewers
71 Video lessons · 69720 Viewers
56 Video lessons · 102030 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.