We launched a new IT training category! Check out the 140+ courses now.

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

Creating sprite sheets with TexturePacker

From: Building Flash Games with Starling

Video: Creating sprite sheets with TexturePacker

So in the last movie I showed how you can incorporate images into your game using that Assets class and embedding the images there. But typically in a game you are going to have lots of different image files, and the problem with that, if you keep them all separated, is that everytime your game loads it's going to have to make multiple network requests. So if this game is embedded on the web, you don't want every single little image file to have to create a new network operation to get it.

Creating sprite sheets with TexturePacker

So in the last movie I showed how you can incorporate images into your game using that Assets class and embedding the images there. But typically in a game you are going to have lots of different image files, and the problem with that, if you keep them all separated, is that everytime your game loads it's going to have to make multiple network requests. So if this game is embedded on the web, you don't want every single little image file to have to create a new network operation to get it.

What's better is to pack all of the graphics in your game into either a single image or sometimes you have too many and you have to go into, let's say, a second or a third, but packing them all together into a single image and this gives you numerous benefits. First of all again, you only have to make one network operation to get the image, and then the other is that you are not having to upload multiple textures on to the GPU, you essentially upload, in our case, it's going to be a single image on to the GPU as a texture and then we can pull the individual pieces of that texture out.

Now for the sky image that we did in the last movie, since it's such a large image we are not going to include that into a sprite sheet, but all of the other images that we are going to deal with can be packed together into a single image. So we are going to be using TexturePacker for this, so go ahead and launch it up. Now when you first see it, it will give you a message saying you are currently using the free version. I definitely recommend if you are doing a lot of this type of work to upgrade and buy the license, it's not very expensive. But for our case we are just going to use the essential version here.

And what we need to do first is to import all of those images that we want to add on to our sprite sheet. So I am going to click this Add Sprites button here at the top. And what I am going to do is to navigate to where my Spacer project is, so mine is in Documents > Flash Builder 4.6 > Spacer and then to that assets folder. And now I need to choose which assets do I want to actually include on my sprite sheet.

So here I have this image sequence of this alien, this little animated sequence, so I want to include those. I want to include this bullet.png, which is the bullet that we are going fire out of the ship, this explosion particle, the hero.png which is our main ship. I am not going to include this font PNG because we'll get to that later in this chapter. I am going to include the logo, the playButton, the smoke particle PNG and the tryAgainButton.png.

Again, we are not going to include the sky because that's such a big image, it's just better for us to embed that directly. Now I am going to click Open, and now you will see all of those various images laid out here. Now we need to do some tweaks to this so we get the format that we want. The first thing we want to do is to come down and we want to check off Allow free sizes. That will essentially create the smallest possible sprite sheet based on the images that we have in it.

Now under Layout we want to change the Layout to Basic and the MaxRect is a more advanced algorithm which actually is only available if you buy the license. If you use that it will actually tint one of your frames red, so you can't really use it in a real game. So we are going leave everything down here at the default, except we are going to uncheck Allow rotation and we are uncheck Trim. Okay, so we are going to leave that at its very basics here. But we can see all of the individual images that are being packed into the sprite sheet, so we have out little animation sequence, we have our explosion particle, our hero ship, logo, buttons; all packed together in this nice little sprite sheet.

So when we export this or publish it, it's going to save two things, first it's going to save a PNG, which is going to be the actual sprite sheet image itself, but then also it's going to export a data file. And this data file is required because when we tell Starling to, let's say, give me this hero texture, Starling needs to know the X and the Y and the width and the height of where in this big sprite sheet that lives, and that's what the data file does.

Now if we come under Output here, we can see there is a lot of different data formats that are supported. The one we are going to use is a data format called Sparrow. The creator of Starling, Gamua, actually created an iOS game framework called Sparrow and Starling is actually based on Sparrow. So it uses the same data format. Now for Data File I am going to click this, because we want to save that data file into our assets folder. So again, make sure that you are in the right folder.

So I am going to go to Documents > Flash Builder 4.6 > Spacer > assets, and I am going to call this atlas. And the reason is when we get into Starling, we are going to be creating what's called a texture atlas. So we are going to call it atlas here and click Save. And you can see by default TexturePacker is also going to save that atlas.png file in the same directory, which is what we want. So now all I am going to do is click Publish, and now if we go back to Flash Builder, you should see if we refresh the project here that we have our atlas.png and our atlas.xml.

So if I load that up here we can see our sprite sheet that was exported, and if I look in the XML, let's say I just open this with the XML Editor here, we can see what has happened here is this created a texture atlas for us. And essentially when we want to request a certain texture out of the sprite sheet, this is the name that we are going to give. So if I want, let's say, the bullet texture, I am going to be able to reference it using a string of bullet, but you can see what the structure of it, it's saying the x, the y, the width and the height of the various positions of the sprites.

So with that atlas created, in the next movie I am going to show you how to create that texture atlas here in Starling.

Show transcript

This video is part of

Image for Building Flash Games with Starling
Building Flash Games with Starling

46 video lessons · 9646 viewers

Lee Brimelow
Author

 
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

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.

Join now Already a member? Log in

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 preferences from 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.