New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Building Flash Games with Starling
Illustration by

Creating the main game class


From:

Building Flash Games with Starling

with Lee Brimelow

Video: Creating the main game class

So now that we have our main entry to our game created in the Spacer class, we now need to create our Game class, which is going to be our root Starling instance. So what I'm going to do is go into the default package here, right-click, and say New > ActionScript Class. Now we're actually going to be organizing the classes in our games into different packages, and we're going to hold this Game class in a package called core, which is going to contain our core files for our project.
Expand all | Collapse all
  1. 2m 9s
    1. Welcome
      45s
    2. Using the exercise files
      36s
    3. What you should know
      48s
  2. 10m 21s
    1. Checking out the finished product
      1m 10s
    2. Downloading the Starling framework
      4m 13s
    3. Installing Flash Builder
      1m 44s
    4. Installing additional tools
      1m 30s
    5. Overview of the Starling framework
      1m 44s
  3. 13m 0s
    1. Creating the Flash Builder project
      2m 40s
    2. Setting up your Starling scene
      6m 7s
    3. Creating the main game class
      4m 13s
  4. 13m 52s
    1. Creating the IState interface
      2m 14s
    2. Creating the three game states
      3m 50s
    3. Building the state machine
      7m 48s
  5. 22m 14s
    1. Creating a static assets class
      2m 3s
    2. Adding images and creating textures
      3m 24s
    3. Creating sprite sheets with TexturePacker
      6m 26s
    4. Creating the main texture atlas
      3m 29s
    5. Creating and importing bitmap fonts
      6m 52s
  6. 14m 16s
    1. Creating the Background class
      5m 55s
    2. Adding the logo
      2m 58s
    3. Adding the play button
      3m 4s
    4. Implementing the destroy method
      2m 19s
  7. 56m 47s
    1. Adding the background
      1m 3s
    2. Creating the Hero class
      6m 14s
    3. Creating the Bullet class
      1m 44s
    4. Creating the BulletManager class
      4m 23s
    5. Using the StarlingPool class
      9m 24s
    6. Firing bullets with the mouse
      7m 24s
    7. Creating the Alien movie clip
      1m 58s
    8. Creating the AlienManager class
      8m 12s
    9. Overview of collision-detection options
      3m 10s
    10. Creating the CollisionManager class
      10m 51s
    11. Implementing the destroy method
      2m 24s
  8. 7m 59s
    1. Adding the background
      1m 10s
    2. Creating the "Game Over" text
      2m 43s
    3. Adding the Try Again button
      4m 6s
  9. 20m 5s
    1. Exploring particle-creation tools
      4m 52s
    2. Adding the smoke texture
      5m 3s
    3. Creating the Explosion class
      2m 6s
    4. Creating the ExplosionManager class
      8m 4s
  10. 11m 5s
    1. Creating sound effects with cfxr
      3m 5s
    2. Adding the sound effects
      3m 42s
    3. Creating the Score class
      4m 18s
  11. 6m 1s
    1. Starling optimization tips
      4m 8s
    2. Helpful Starling resources
      1m 53s

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 ...
Building Flash Games with Starling
2h 57m Intermediate Jul 05, 2012

Viewers: in countries Watching now:

Join Lee Brimelow in this project-style course that teaches how to build a Flash-based game with Flash Builder 4.6, Flash Player 11, and the Starling framework. Starling, a pure ActionScript 3.0 library for advanced graphics, extends Flash Player 11's support for the modern GPU (graphic processing unit) to enable visual presentations and games in the browser or as a mobile app.

Starting with installation and configuration of Starling and creation of a Flash Builder project, the course shows how to prepare and import graphical assets, create MovieClip classes from sprite sheets, manage various gaming objects, detect collisions, and add both particle and sound effects. The finished game can be deployed to any browser or mobile device that integrates Flash Player 11, which was released in September 2011.

Topics include:
  • Downloading and installing Starling and Flash Builder
  • Creating the project
  • Creating the main game class, static assets class, and other classes
  • Building the state machine
  • Creating a static assets class
  • Adding images
  • Creating sprite sheets with Texture Packer
  • Creating and importing bitmap fonts
  • Detecting collisions
  • Adding particle effects
  • Adding sound effects
Subjects:
Developer Web Games
Software:
ActionScript Flash Builder Flash Player Starling
Author:
Lee Brimelow

Creating the main game class

So now that we have our main entry to our game created in the Spacer class, we now need to create our Game class, which is going to be our root Starling instance. So what I'm going to do is go into the default package here, right-click, and say New > ActionScript Class. Now we're actually going to be organizing the classes in our games into different packages, and we're going to hold this Game class in a package called core, which is going to contain our core files for our project.

And for Name we're going to give this a name of Game. For the Superclass, this is going to need to sub-class sprite, but again, we're not going to be using flash.display. Sprite, we're using starling.display.Sprite, so that's a very important distinction. It can be a little difficult at first when you first begin with Starling, because again, the class names are often times exactly the same as the traditional display list, so you need to make sure you are using the correct one. I'm going to click Finish now.

And now we have our core package with that Game class inside of it. Now you'll notice the Spacer class still has an error and that's because the Game class is not in the same package. So what we're going to do is to move that Spacer class into the core package, we're just going to drag it like that, and then we can click OK, and it's going to tell you that there is errors but don't worry about it, just click Continue, because the error will be corrected as soon as it gets into the core package. So now both our Spacer class and our Game class are in that core package.

So the first thing I am going to do in the constructor, and we don't have to call this super constructor here, is we need to listen for the ADDED_TO_STAGE event, because we don't want to do anything with our main Starling instance here, until we know it's been added to the stage. So we're going to say addEventListener. Now here again, we're going to be using the ADDED_TO_STAGE event, but this is the one that's actually in Starling, so when you import it, you want to import the starling.events.Eventclass. And you'll notice it has a lot of very similar methods or events rather than the traditional event class. Now there is also some other ones in here that are specific to Starling.

But we're going to use the ADDED_TO_ STAGE event, and we're going to have it call a function called init. So let's go ahead and create that function. So private function init, the event object again is going to be of type starling events.Event. We're not going to be returning anything here. So now inside of this main class, we're going to have an enter frame loop, and this is going to serve as our main game loop. In the init event, register and listen for the ENTER_FRAME event. So again, addEventListener, this is going to be event.ENTER_FRAME, and we're going to have it call a method called update.

Quick tip in Flash Builder, if you hit Command+1 or Ctrl+1, it will give you this quick fix menu, it will give you the option to create that method called update. And all we have to do is to add in the event object to that. So I'm going to say event, and again this is going to be of type Event. And that's our basic Game class created. Again, the main thing to understand is that once we're in our main Starling instance here, we're now going to be working with the Starling version of the display objects, so you're not going to using regular movie clips and sprites; we're now essentially in Starling world.

Here is the main entrance to our game, which is our Spacer class, this is what extends flash.display.Sprite. But again, once we're in our Starling instance, we have now switched to using the Starling versions of all of those classes. Now it is possible to mix regular Flash display list with Starling, but it's not recommended. If you're building a game, you should try to do everything inside of Starling, even things like menus and high scores and things like that, and we'll get into how you can accomplish that later in the course, but this is the main structure for our Game class.

There are currently no FAQs about Building Flash Games with Starling.

 
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.
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 Upgrade 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 Building Flash Games with Starling.

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

Notes cannot be added for locked videos.

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.