Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Reviewing the game structure

From: Flash Professional CS5: Creating a Simple Game for Android Devices

Video: Reviewing the game structure

Let's begin by reviewing the start file that already has basic game structure implemented, including graphics as well as ActionScript code. Let's start with the graphics, because on this introScreen layer is this intro screen, and I'll just double-click on it. You can see it contains animation, as well as a Play button right here. So you click the Play button and you'll get into the game. Let's go back to Scene 1. I'll turn off the introScreen.

Reviewing the game structure

Let's begin by reviewing the start file that already has basic game structure implemented, including graphics as well as ActionScript code. Let's start with the graphics, because on this introScreen layer is this intro screen, and I'll just double-click on it. You can see it contains animation, as well as a Play button right here. So you click the Play button and you'll get into the game. Let's go back to Scene 1. I'll turn off the introScreen.

There is an options menu, with an Exit button that will be used-- I'll turn that off-- and an endScreen that will populate the results. I'll turn that off. Then we have this text layer which contains some various text items. These happened to be dynamic text fields that will show the score, the lives, as well as the Level the person is on, and lastly we just have that background. So those were all the game's screens set up and various graphics, most of the graphics we'll need.

And notice also in the Library panel there are some various graphics that will be used. So I am going to click back on the Properties panel. Now, let's take a look at the Actions layer. It's right here, in that first frame, is some ActionScript code. So let's go to Window, open up the Actions panel, and let's review some of this code, this basic game structure that's currently set up. So right up here at the top are going to be all of the variables. Okay, so there are four variables up here at the top, this INIT_GAME.

There's this START_PLAYER State. There's the PLAY_GAME State and the END_GAME State. So at any point in time, the gameState is going to be equal to one of these items up here. Okay. We want to be aware of what gameState we're in at all times. We need to set up those variables first. Next up is the setup, so right in here, this is where we'd sort of turn on and off any graphics that we'd want to deal with, maybe adjust the screen size.

That's all done in the setup, so in this case we're turning off the endScreen and we're turning off the optionsmenu. Okay let's scroll down, because next up we have this introscreen, and for this introScreen we have a Play button, and when it gets clicked on it fires off this clickAway function, which in turn moves the introScreen off. That's when it calls to this function right in here. function moveScreenOff this first line. I'll just do two forward slashes to add a comment.

So basically "Move the screen off." That's what this line does. Right in here, this is where we establish the gameState, STAY_INIT_GAME. Okay. Not only that, but this trace statement is going to give me, in the Output panel, this word STAY_INIT_GAME. Trace statement will appear in the Output panel. And then, lastly for this, we are to go ahead and fire off the gameLoop function at the frame rate of the movie.

This is important because this is going to keep track of what gameState we are in, okay. At the frame rate of the movie, that might be something interesting to check out, so let's go ahead and take a look at it. I'll minimize the Actions panel, and I'll just click on the background, right here for my stage, so my document is selected. And notice in my Properties panel frames per second, 24. So the gameLoop would fire off 24 frames per second, okay. That's quite a bit, and I am going to seeing a lot of these trace statements, so I really want to take that down to 1.

Okay, so just for testing purposes, I want to change the frames per second to 1 frame per second. So at that rate, this function is going to get called 1 frame per second. So let's go ahead and scroll down a little further and take a look at gameLoop. Okay, for this gameLoop function, it's basically going to keep track of all of the games state the user is in, okay. So if they're in the STATE_INIT_GAME, if gameState is set to STATE_INIT_GAME, fire off this function. If it's set to START_PLAYER, fire off the START_PLAYER player function.

PLAY_GAME, fire off that function. STATE_ END_GAME, then fire off the endGame function. So it's constantly checking to see what state you're in. If I scroll down a little further, I should see all of these functions down below, so let's take a look at initGame. So when they click the Start button, it fires off this initGame, and right in here, this is where we set up all the graphics and everything.

Not only that, once they're all set up, we can change the gameState to START_PLAYER. Okay. Trace gameState, its going to just show me these words in the Output panel. But then next up, with that set to START_PLAYER, it's going to fire off this function startPlayer, so this is where we basically create the player that you're going to control. Okay, that's going to go right in here. Once he is set up, STATE_PLAY_GAME will show up in the Output panel, and then it will fire off this function called the playGame.

And right in here, this is basically where you set up the enemies, explosions, et cetera. So there is a quite a few thing that are going to go right in here, so there might be multiple function calls in here. As I scroll down, makeEnemies, we should see this appear. testForEnd right in here, this is where basically "Check to see how many lives the user has etc." some other things. Check their level. All of that.

But again, you can check that and all we're doing here is we are going to set the gameState to STATE_INIT_GAME, which in turn is going to go ahead and initialize this function, which is going to remove the game, which is going to appear this trace statement. It's going to turn on the endScreen and then go ahead and show the results. So if I scroll up, testForEnd fires off of this and just basically puts everything in place at the closing screen, all of that good stuff.

All right, so that's the basic structure for this game. Notice right here everything is really powered by this gameStates function, which controls all of these other functions that do various things. And since I've dropped my frames per second down to 1 frame per second, we should see various statements in our Output panel, so I am going to close that Actions panel. I am going to just go ahead and increase the size of this panel because right in here, in my Output panel, I am going to see all of these trace statements. So I am going to go to Control > Test Movie.

I am going to test it in Flash, and we'll see this animation go slow because it's only going 1 frame per second. That's fine. But watch what happens if I click on the Play button, and we'll just keep an eye out for my Output panel. Click Play. There we are. So it initializes the game, it starts the player, play the game so it can set up all of the enemies, into the game, and then remove the various things and show the results.

So that's the basic game structure that's set up. I'd say it's looking pretty good. It's really just a matter of populating all of these functions with various things, and one of the first things is going to be to make sure we set up our screen appropriately so our content fits appropriate regardless of what size your screen is.

Show transcript

This video is part of

Expand all | Collapse all
  1. 1m 48s
    1. Welcome
      1m 0s
    2. Using the exercise files
      48s
  2. 7m 16s
    1. Understanding the user
      4m 2s
    2. Flash content on Android devices
      3m 14s
  3. 17m 28s
    1. Reviewing the game
      1m 50s
    2. Creating a file in Device Central
      5m 39s
    3. Reviewing the game structure
      8m 23s
    4. Adding code snippets
      1m 36s
  4. 36m 13s
    1. Animating the intro screen
      8m 13s
    2. Moving the player
      8m 13s
    3. Adding enemies
      6m 49s
    4. Adding movement
      4m 16s
    5. Adding chance and randomness
      8m 42s
  5. 34m 30s
    1. Adding lasers
      8m 14s
    2. Detecting collisions
      7m 57s
    3. Adding explosions
      6m 26s
    4. Removing assets from the stage
      8m 50s
    5. Adding audio
      3m 3s
  6. 33m 12s
    1. Adding scoring and levels
      7m 41s
    2. Subtracting lives and ending the game
      4m 26s
    3. Creating a results screen
      5m 8s
    4. Displaying the score
      6m 57s
    5. Saving and loading game results
      9m 0s
  7. 17m 14s
    1. Detecting movement with the Accelerometer
      6m 39s
    2. Using the swipe gesture
      4m 42s
    3. Using hardware keys
      5m 53s
  8. 23m 18s
    1. Handling exits and idle mode
      3m 31s
    2. Handling activation and deactivation
      6m 14s
    3. Optimizing graphics
      7m 14s
    4. Optimizing ActionScript
      6m 19s
  9. 34m 41s
    1. Creating the application files
      8m 23s
    2. Creating the app (Mac)
      5m 5s
    3. Creating the app (PC)
      7m 19s
    4. Publishing to an Android device (Mac)
      7m 7s
    5. Publishing to an Android device (PC)
      6m 47s
  10. 8m 56s
    1. Uploading to the Android market
      7m 7s
    2. Downloading from the Android market
      1m 49s
  11. 1m 22s
    1. Next steps
      1m 22s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Flash Professional CS5: Creating a Simple Game for Android Devices.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.