Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So now we have our menu state essentially completed. The last thing we have to do is remember that for each state when we change the state it's first going to call this destroy method, so that our state can actually clean up itself, because again, we want to remove all of the things from the display list, because we don't want to be taking up memory while a different state is happening. So let's fill in this destroy method now. So there's some nice helpful methods that are in Starling that are not in the traditional Flash display list API.
And one of them is a method called removeFromParent. So the first thing I'm going to do is to remove the background, so I can say background, and then call the removeFromParent method, and I can pass in true if I want it to also be disposed, and that will do things like unregister any event listeners that have been registered, so we're going to pass in true there. And now to make sure we totally clean up, I'm also now going to set background = null.
So we're going to do the same thing for the logo, so logo.removeFromParent, put in true, because we want to dispose it, and let's set logo = null. And lastly let's do the play button, so we'll do play.removeFromParent(true); and we'll also set it to null. When we change the state to the play state, the first thing that's going to happen is this destroy method will be called and we can actually dispose of it properly.
Now the last thing we need to do is to get rid of the menu state itself, remove itself from the game's display list, and here we can use the removeFromParent method and pass in true. So this is a really handy method to be able to have in order to help you easily manipulate the display list. Let's go ahead and test it now. We can see it's launched up, and when I click PLAY GAME, everything has disappeared, because again the menu state has removed itself, but remember now the play state doesn't have any visuals on it whatsoever.
So in the next chapter we're going to be building out that play state, which is going to contain all of our actual game play.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97140 Viewers
61 Video lessons · 84431 Viewers
71 Video lessons · 68637 Viewers
56 Video lessons · 101128 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.