Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In Flash Professional CS5: Creating a Simple Game for Android Devices, author Paul Trani shows how to translate existing Flash skills from the web to mobile devices while designing a game in Flash and publishing it as an AIR for Android app. The finished application includes collision detection, random enemy creation and movement, shooting capabilities, multiple levels, and even a high score screen. This course also goes beyond game functionality and shows how to use mobile capabilities such as the accelerometer and gestures to control graphics, use the hardware keys to activate menus, and also how to optimize content so it plays well on mobile devices. Also included are instructions for distributing an app through the Android Market. Exercise files are included with the course.
Once the player has completed the game, you want to go ahead and display the results-- so, how well the player did. And if they've done really well, you want to give them the opportunity to enter their name to be added as the highest scorer. This is all going to be done in this endScreen layer. If I turn that on, you can see this endScreen movie clip. There is its instance name. I'll just double-click it, and in here we have a couple of different elements. First off, we have this high score text field. This is a dynamic text field.
So again, this is selected, and what will be populated in here is how well they've done, their score, what level they got to, information like that. If they've done pretty well, what's going to happen is they're going to have the opportunity to enter in their name in this input text field, and it's known as High-score name. When they click Enter, it's again known as enter_btn. It will actually populate this same dynamic text field with, again, confirmation of how well they did with their name, and then the player can go ahead and play again.
So that's what I want to do, and I'm going to do this all using ActionScript. So, I'm going to go back to scene 1 and I'm going to this Actions layer, that first frame, because right there that's why I'm going to add a code snippet. I encourage you to check out the Code Snippets video if you do not have these code snippets, but what I want to add is this Show Results code snippet. So I'll just double-click on it and it adds that code snippet right here. So I want to move it, but first off, I want to go ahead and review where it's going to go. Okay, so I have this Show Results function, and right in here, there is a couple of things that happen, and I do want to display the high score, but I want to have these first two lines, what they do is they basically hides the text field and the Enter button, so that's what goes on right here.
Go ahead and turn off the enter button and turn off the high-score name. Just by default go ahead and do that. Next step, what this line does is we need to basically enable the play button, so enables the play button. That's what happens right here. Go ahead and make sure the play button works. And what that play button does is if they click on it--and again regardless of how well they do, we want to make sure this play button works-- but when they click on it, it's going to fire off this function called Move Screen Off, which is going to move off the endScreen.
So if you do recall up at the top, this is actually being used for a couple of different things, so I'll just scroll up. moveScreenOff is used for the intro screen as well, but I just want to point out then it's going to go ahead and slide its X position off. And quite frankly, I need to just make sure that it does get reset back to zero, so if you play the game a couple of times, I want to make sure that endScreen always starts in the correct position. So in this endGame function, that line 323 endScreen X position is equal to zero.
If they've played the game a couple of times, you want to make sure that the game always starts out at zero and doesn't appear off to the side, because again, if you play it a second time, you wanted to make sure that it is in the right position. Okay, so again, that's the code currently in here, and what I want to do is I want to go ahead and add the results, so Show Results, and that's where this code snippet comes in right here. I'll just go ahead and take this code snippet, and I'll cut it and paste it right in here at about line 359.
Paste it on there. Right here Show Results, if the score is greater than zero, which is what this says, then go ahead and in that high score text field it says, "Hey you know you made it to whatever level you made it to, with a high score of whatever your high score is that's greater than zero," and this \n just gives it a line break because on the next line it says enter your name below. All right, so right here, come back over here. I'll just add another comment: turns on the enter button and the input text field.
Again, what I turned off up here, I need to go ahead and turn on if they did an okay job, if they've killed the at least one guy, then they get the chance to enter in their name and I make sure the enter button works as well. All right, moving on down, quite frankly, if they did a terrible job, your score of zero is what this really says and does not be zero, so here's where you can add whatever sarcastic comment you want, but know that this is your 'do better next time' line right here within this Else statement right here.
And of course the Enter button, as soon as they click on the Enter button after it gets turned on here, after they click on it, it's going to go ahead and display their results. So it says, "Hey, great job," just confirming how well they did, their name that they've entered in, that text field, what level they made it to, and what their score is. So again, if I can just show you that, after they enter their name, they're going to click Enter that's going to display that information back up in here. And I need to turn those two items off when they do hit the Enter button.
So again, right in here, I'll just add a comment if I could about line 376: hides the enter button just selected and the input text field. That's what happens there. It hides those two, but they can still click on that play button and they will and play the game again. All right, everything seems to look pretty good, but again, I want to go ahead and test this out by playing the game, so let's just test this out real fast.
Click play, and again I just need to destroy at least one of the enemies. Okay, I've destroyed one. All right, so you made it to level 1 with a high score of five. Enter your name below. So again, I can just jump in here, enter in my name in this input text field.
This Enter button, when I click on it, it will display my results, as well as my name, and these two items will disappear. Sure enough, that happens "Great job, Paul! You made it level 1 with a high score of 5. All right, so I have this working out great. You can see that it's populating the high score screen, but what I want to do next is I want to go ahead and save these results as my current high score. And each time I play the game, I want to go ahead and try to beat the previous high score, but again that's going to happen in the next lesson.
There are currently no FAQs about Flash Professional CS5: Creating a Simple Game for Android Devices.
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.