Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Creating game play is one thing, but just as important is removing this game play and showing the end screen. So let's start off and I'm just going to go ahead die immediately. Wait for those guys to reach the bottom. All right, so this is the Results screen. As you can tell, there are some UFOs that just are frozen in time are right here on the screen, and not only that, my spaceship is actually moving around, and it's still generating these lasers even though they're not moving.
So just as important as creating this gameplay, I need to actually remove all of these elements. And most of these elements are actually dynamically created, so I need to go through and dynamically remove all of those items. And I am going to do this by looping through these arrays, so I need to remove the explosions, the enemies, and the lasers. So in the Mobile Game folder in our Code Snippets panel right down here, Loop through Items in an Array. That's what I want to add.
It adds this code right here. All right, so I'll just hit Return to bring that up. So it loops through an enemies array, and it will do something to each one of those items. Well, I actually want this to happen when the game is over with. So I am going to go ahead and move this code. I am going to move it into the removeGame function. So I am going to cut it. I am going to scroll up right here at line 325, here is my removeGame function, and I am going to paste it right in there.
And I'll just click that Format button, so everything indents appropriately. And now it says for the enemies array, loop through it and then do something for each item. Now if you do recall what we're doing for each one of these items is we already have these removeEnemy functions, removeLasers, and removeExplosion functions. So I want to use these same functions for removing all of those elements. So I'm just going to go ahead and copy this function name or removeEnemy. I am going to come down in here and paste it right over that comment.
And I am going to go ahead and call that function, and I am going to pass the variable i into it. So I'll copy that and paste that right in there. So it will loop through the entire length of the array, everything in that array, and it will remove all of those enemies. All right, I need to do the same thing for the lasers, so next step is going to be Remove lasers. Take all of this for loop, paste it below. And for this array it is actually called Lasers. Not only that, I don't want to establish another variable with the same name. I actually need to change that variable name. I'll just change it to j. So wherever I see i I'll just change to j, just like that. And removeEnemy, well, no I don't want to remove the enemy; I just want to remove the Laser and type j right in there.
All right, so far so good. I'll copy this for loop again, because again I need to do the same thing for the Explosions. Paste that in. And again, for the explosions, I'll just type in k for the variable. The array, again, is going to be explosions. K for that variable name, just like that, removeExplosion, just like that, type in k, and there we are.
So that will loop through all those arrays and remove all of those elements. That's great. That's exactly what I want. I just need to do a couple more things in here. I need to go ahead and remove the player, and that's as simple as typing in removeChild(player). There is only one. I can call it directly by its name. And then to stop that laser timer, I'll just type in laserTimer. Again, that's what actually makes all of those various lasers, and all I need to do is stop it, just like that.
All right, I'd say that it looks pretty darn good. Again, this is in the removeGame function. And again, when that endGame gets called, it's going to remove basically all the game elements like its shown in here, and then of course it shows the endScreen and does some other things. So let's go ahead and run this: Control > Test Movie. And I am going to quickly die in here, so you can see the results screen.
There we are, a nice clean results screen. I don't have any of the UFOs frozen or any lasers frozen or explosions, and I'm not controlling the player anymore because the player doesn't exist. That looks great. I have ended the game correctly. Now, really the next step is to start to add some various scoring on this final screen.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99862 Viewers
56 Video lessons · 112986 Viewers
71 Video lessons · 81818 Viewers
131 Video lessons · 39262 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.