Start learning with our library of video tutorials taught by experts. Get started

Flash Professional CS5: Creating a Simple Game for Android Devices

Adding explosions


From:

Flash Professional CS5: Creating a Simple Game for Android Devices

with Paul Trani

Video: Adding explosions

Let's go ahead and take a look at where this game currently is in its development stage. I'm going to click Play, and if I move this SWF over a little bit, notice that there is a couple of collisions going on here, these lasers with these UFOs, and we should see these trace statements appearing. So I need to actually have an explosion when these lasers hit the UFOs and when these UFOs hit the bottom or hit my player. So I need to attach this explosion from the library in a particular position.
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

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Flash Professional CS5: Creating a Simple Game for Android Devices
3h 35m Intermediate Feb 15, 2011

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.

Topics include:
  • Designing for mobile platforms
  • Creating and optimizing game graphics
  • Adding random movement and interactivity
  • Moving players based on the accelerometer
  • Using gestures
  • Detecting collisions
  • Implementing audio
  • Adding scoring and levels
  • Implementing a high score screen
  • Publishing an app on both Mac and Windows
  • Uploading to the Android Market
Subjects:
Developer Web Games Projects
Software:
Device Central Flash Professional Android
Author:
Paul Trani

Adding explosions

Let's go ahead and take a look at where this game currently is in its development stage. I'm going to click Play, and if I move this SWF over a little bit, notice that there is a couple of collisions going on here, these lasers with these UFOs, and we should see these trace statements appearing. So I need to actually have an explosion when these lasers hit the UFOs and when these UFOs hit the bottom or hit my player. So I need to attach this explosion from the library in a particular position.

So let's go ahead and go to the Library panel, because in the Library is going to be this explosion movie clip. I'll just double-click on it. Notice it contains a couple of frames of this explosion. So this is what I want to attach to the stage and then play, and then this last frame is just a stop action so it doesn't continually loop, but that's basically what my explosion movie clip is. I am going to go back to Scene 1, and in this first frame of this Actions layer is where I want to add a code snippet.

So I am going to open up my Code Snippets panel. In the Mobile Game folder, right down here is Make Explosion. Please refer to the Code Snippets movie if you don't have this. But all I am going to do is just double-click on Make Explosion, and it adds this code here. So what happens is it creates an array called explosions. So here's the explosions array, and then there's that function that's going to deal with this array. But the first thing I'm going to do is I'm going to go ahead and take this variable and I'm going to cut it, and I'm going to move it up to the top of my Actions panel. Right in here, just beneath Lasers, I am going to go ahead and paste in this variable explosions.

So now Flash knows that explosions is an array. Next up, I want to go ahead and create the array, and that's what this line does. I am going to take that in the comment. I am going to cut it, and I want to create the array when the game starts. So I'm going to scroll up toward the top, and right in here, when the game initializes, these other items are created, and sure enough, just beneath Lasers, that's where I want to paste in my explosions array.

So I will hit Tab just to even those out. So the explosions array is created. Now, let's scroll back down, and let's take this. So this Make Explosion, I'm actually going to take this and move this up as well. I am going to cut it, and I am going to move it up just beneath my testCollisions, about line 237 and I'll paste it on in, and let's take a closer look at this. It says add an instance of explosion from the library to the stage, and it's putting it at 400 pixels in by 300 pixels down.

That's the X and Y. So let's go ahead and make sure that there is an explosion in my Library. Sure enough, its linkage name is Explosion, capital E. So here is my makeExplosion function call, and it's going to go ahead and pass in these two numbers, which is just the position of this explosion. But this makeExplosion actually creates this tempExplosion. That's the name of this new movie clip. So it basically grabs this Explosion symbol, puts it on the stage-- that's what this does--and it puts it on the stage, its x position being ex, which is right here.

So it's pretty much whatever property that gets passed in. If this is 400, well ex actually equals 400. So it's the equivalent of having the position be 400 right there. I'll just undo that. Same thing for the y; whatever number gets passed in to this function right here again becomes the y position, and then it adds it to the stage depending on those two positions, and then it puts it inside of this Explosions array. So that's what it does. It pulls an item from the Library, places it on the stage at this particular location is how this works.

All right, I'm going to go ahead and just remove this comment, and quite frankly, I don't want to just call this function as it is right here. What I want to do is I want to determine when the--say for instance the laser hits the enemy, then make that explosion. Sure enough, that's right here. So I'm going to go ahead and take this line and I'm going to cut it, and right in here where the laser hits the enemy, well, I'm going to go ahead and replace that trace statement with this makeExplosion.

That's all well and good, and that will work when it gets hit, but I need to be concerned about the position now because I want to position it at the same location as the tempEnemy. So I am going to copy that word and paste it right in here where it did say 400. Remember, that's the x position, so the tempEnemy's x position, and the second parameter right here is going to be the y position. So make an explosion exactly where that tempEnemy is and attach it to the stage and actually put in the array.

All right, that looks good, and again that's just when the laser hits the enemy. Well, I'm going to copy this line because I also need to determine when the enemy hits the bottom or when the enemy hits the player, I want that enemy to blow up. So that's right here, trace("enemy scores"). Well, I am going to go ahead and replace that with that Make Explosion now as well. All right! So we should see all of these various explosions appear on the screen.

Notice that nothing is being removed from the stage or anything like that just yet, but we should see lots of explosions, which is always cool. Let's click Play, and again, as I come down, I'll go ahead and shoot this guy. You can see all of those explosions as I hit him, and then watch him. As he hits the bottom, it'll go ahead, and explode or has they hit my player, you can see all of these explosions all over the place. So that's great. It's all working very nice. The only issue is is that these UFOs are invincible, and the next step will be to actually remove items from the stage.

There are currently no FAQs about Flash Professional CS5: Creating a Simple Game for Android Devices.

Share a link to this course
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.
Upgrade now


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.

join now

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
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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