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

Flash Professional CS5: Creating a Simple Game for Android Devices

Optimizing graphics


From:

Flash Professional CS5: Creating a Simple Game for Android Devices

with Paul Trani

Video: Optimizing graphics

One thing you are going to want to do with your game is you are going to want to optimize all of the graphics so it plays well. This is particularly important on mobile devices, because, again, they just have smaller processors. They are running on about a 1-GHz processor, and in general, I need to make sure these graphics perform well. What's interesting is that on mobile devices, vector graphics don't perform as well because these small phones have to do all these calculations of all of these various curves for vector drawings.
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

Optimizing graphics

One thing you are going to want to do with your game is you are going to want to optimize all of the graphics so it plays well. This is particularly important on mobile devices, because, again, they just have smaller processors. They are running on about a 1-GHz processor, and in general, I need to make sure these graphics perform well. What's interesting is that on mobile devices, vector graphics don't perform as well because these small phones have to do all these calculations of all of these various curves for vector drawings.

So what I want to do is I want to take my important vector graphics and convert them into a bitmap. Flash actually allows me to do that. For instance, if I just come to this text layer right here and I'll just zoom in, for instance, on some of this text here, well, this is actually quite frankly, this is some text here that is vector information. Okay, so what I want to do with this is I am just going to drag this text into the library, and I am going to call it text.

Okay, so this could be anything on the stage. In this case, it's just some text. But I want to take this vector information and in the Properties panel, I want to cache this as a bitmap. So under display, cache this text as a bitmap. This happens at runtime. So this is exactly what I want to do and this is going to work out quite well. Well, for most of my game play all of the graphics are actually dynamically created.

They are pulled from the library, if you will, and what I need to do is I need to go ahead and cache these as bitmap as well. But again, they're added using ActionScript, so I need to use a code snippet to be able to make sure those are all cached as bitmaps. So right down here, there is Optimize Graphics. That's the code snippet I want to use. Just double-click on that, and it's going to add basically these two code snippets right in here.

Okay, so this first comment says, this is great for graphics that move along the x and y position or not at all, okay. So this is a perfect case, for instance, for my lasers and my player. So that's what I'd want to use this for, cacheAsBitmap = true. The second one down here--and I'll just hit Return a couple of times-- this is great for graphics that scale, rotate, or even maybe change their alpha or their transparency. So for this one, I actually want to use this for my enemies.

Okay, just like that. All right, so let's start with this first one right here. I am going to take this line, I am going to copy it, and I am going to go up to where my player is created. I should have, actually, a start player right up here. Scroll up a little more, right in here. Here's my start player, and I'm going to look to where these properties are added, because the CacheAsBitmap is basically a property, so that's what I want to add, and I am going to add it before the addChild, before I get to put onto the stage.

I am going to paste in that line. So for instance name here, that's going to be player, all right. So my player is going to be cached as a bitmap. Let's take a look. We have this LaserTimer.start (). That's referring to the laser timer timer class. So I'll scroll down, and that's right here. This function, line 171, right in here after the x and y, I want to go ahead and paste in that line, and for all the tempLasers, go ahead and cache them as bitmaps as well.

Okay, so those two are set up. Let's scroll down a little further, and I don't need these lines, so I am just going to delete those lines of code, and right in here I am going to go ahead and use this cacheAsBitmap matrix, and that's going to enable me to cache all the different instances of these enemy spaceships. So as they rotate, it's actually going to cache all of those rotations as a separate bitmap is what this does right here. But I still also need to include the cacheAsBitmap as well. So I am going to take these two lines, I am going to cut them, and I'll just delete those comments down there at the bottom.

Now let's scroll up where we have the makeEnemies. Here we are, makeEnemies, about line 229. Here is this function, right in here, sure enough. Here is that property for moving its x position, and I'll paste those two lines right in here. So again, I'm dealing with tempEnemies, so I am just going to copy that instance name and paste that in where it says instance_name_here, just like that. Okay, there we are, so even the tempEnemy as it rotates, because it will rotate as well, well, I want to go ahead and cache each one of those as a bitmap.

You might be asking, what do you do with animated graphics? Well, let's take a look, because there is that explosion as well. So here's this explosion, and I'll just double-click on it, and I'll zoom in on this explosion. You can see that this is vector data right here, okay. So this is just a vector line that I created in Flash, and I want to replace these actually with bitmaps. So the cacheAsBitmap or cacheAsBitmap matrix does not work on animated movie clips like these, because there's one frame, two frame, and then three frames.

So in this case what I want to do is I am going to create a new layer and I'm just going to import some bitmaps of that same explosion. So I am going to import to stage. In the graphics folder, I am going to select this Explode_1, and since these are all numbered, it's going to bring in all three of these, and that's exactly what I want. So this is PNG file that was created actually from this original vector. I just took a screenshot, cropped it down, and saved it as a PNG file with transparency, and I'm going to select Open, and it's going to bring in this entire sequence.

So those three images, I'll select yes, and there they are. I can first kind of space these out, each keyframe, so these explosions appear at the appropriate time. And not only that, I can get rid of these two layers below just by deleting them, clicking that trashcan, and deleting those two layers. The last thing I am going to do is I am just going to go ahead and like center those graphics kind of like that. All right, there we are, and I'd say we're good to go.

Lastly, here are my PNG files. I can go ahead and move those into the assets folder, just to do a little bit of cleanup. But again, for animated graphics you might consider using bitmaps by importing them; otherwise, you can use cacheAsBitmap or cacheAsBitmap matrix, just as long as you are basically taking most of your vector content that's moving around a lot and converting it to bitmap. It really is going to help performance on a device.

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