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

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

Adding images and creating textures

From: Building Flash Games with Starling

Video: Adding images and creating textures

So the first type of asset that I'm going to show you how to include is a simple image asset. So in our game we have a background which consists of some stars, and that's just a simple PNG file. If we look in our assets folder, it's called sky.png and that's what it looks like. So we're going to want to embed this so that we can use it in our game. So the way we embed a PNG or any other type of image asset, and you're used to this if you've been doing Flash for a while, is to use the Embed Metadata.

Adding images and creating textures

So the first type of asset that I'm going to show you how to include is a simple image asset. So in our game we have a background which consists of some stars, and that's just a simple PNG file. If we look in our assets folder, it's called sky.png and that's what it looks like. So we're going to want to embed this so that we can use it in our game. So the way we embed a PNG or any other type of image asset, and you're used to this if you've been doing Flash for a while, is to use the Embed Metadata.

So we can say Embed and then give a source property and give it the path to the PNG file that we want to include. Well that's in the assets folder, and it's called sky.png. And then next we need to give a class which is going to be used to instantiate that image. So again, we're doing everything as static, but this is going to be a private static var sky and this is going to be of type Class.

Now when we're dealing with images, we're actually going to be creating textures out of these images, because remember, when you're running on the GPU using Stage 3D, everything is essentially triangles and the way in which you display things is to actually put a texture onto those triangles. Now it's important that we don't repetitively create textures. So for instance, this sky image we're going to create a single static texture here in the Assets class and any time we want to use that, anywhere in our game, we're going to use that single texture object, because remember everytime you create a texture, it has to upload it to the GPU and it's also increasing the memory that your game uses.

So you want to create the very least amount of texture as possible and make sure you reuse them. So we're going to create a texture out of this and this is going to be a public static texture, so that we can reference it from outside of this class. So we're going to say public static var and I'm going to call this skyTexture, and this is going to be of type texture, and the package is starling.textures.Texture. Okay, so now with that created inside of our init function, we're going to instantiate that texture or create that texture.

So I'm going to say skyTexture =, now I could say new texture here, but there is some helpful static factory methods on the texture class that we can use. So I'm going to say texture, and there is a fromBitmap static function available, in this we pass in a bitmap instance which is going to be used to create the texture, and for that we pass in a new instance of that sky embedded bitmap. So now after this initialization function is called from our game, main game constructor function, anytime we need to display that sky image, we're going to reference this skyTexture.

So again, it's only going to be in memory one time uploaded to the GPU, and anytime we need to use it we're going to reference that single texture. So again, that's the basics of incorporating an image file such as a PNG and a JPEG and creating it into a texture for Starling.

Show transcript

This video is part of

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

46 video lessons · 9363 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

Are you sure you want to delete this note?

No

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.