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

Preparing a sprite image for animation

From: CSS: Animations

Video: Preparing a sprite image for animation

In this tutorial, we're going to look at the steps involving creating a sprite image to use in our CSS animations. Then in the next tutorial, we'll actually use this image and put it in motion with an animation. This is the image that we'll be creating. It's a really big image with all the steps to our animation in it. So you can see it's pretty big, and there's a lot of individual images that we'll put together to make this one large image. This CSS animation technique is best for highly illustrated animations and usually ones that are traditionally drawn and traditionally animated with animation software. Typically these animations will be created first in something like After Effects or Flash.

Preparing a sprite image for animation

In this tutorial, we're going to look at the steps involving creating a sprite image to use in our CSS animations. Then in the next tutorial, we'll actually use this image and put it in motion with an animation. This is the image that we'll be creating. It's a really big image with all the steps to our animation in it. So you can see it's pretty big, and there's a lot of individual images that we'll put together to make this one large image. This CSS animation technique is best for highly illustrated animations and usually ones that are traditionally drawn and traditionally animated with animation software. Typically these animations will be created first in something like After Effects or Flash.

We won't cover how to illustrate and animate this in those programs, but we'll be covering how to bring these animations to life with CSS so they can live natively on the web. So let's get started with our image. Sprites are often used in web design. Though they typically look something like this, they're usually a whole bunch of icons that we want to display in different places on our web page all combined into one big image, so we can just reference one image to get all our icons. When we use sprites for animation, the same concept applies. We collect up each frame of our animation, if you want to think of it that way, and assign this big image as the background to a div and then move that background to create animation.

So if we hop back to Photoshop, this is the image that we'll be creating for our animation. The source for this sprite image was an image sequence of an existing traditional animation exported from the animation program, and what we got out of that was a list of images like this. It doesn't matter which animation program you use to export these images but all of the major ones have the ability to export a sequence of images in some way. The resulting list of images is more important than what you used to export them. The important thing is to make sure that all your images are the exact same size, and generally, that will happen by default.

These particular images were prepared by a friend of mine who does a lot of traditional animation. Our next step, once we have all our images in the sequence is we'll need to arrange this into a sprite that we can use in CSS. There are a number of automated tools for making sprites, but I found that most of them don't give you enough control over what order your frames will show up in. We only have a handful of frames in this case, so it's easier to create our sprite image by hand. We'll go into Photoshop to start this process. We'll start by pulling the images we have into Photoshop. We'll use a built-in script to do the hard work of importing each of our images for us.

We'll go to File, then Scripts, and Load Files into Stack. Then we'll browse to where we have all our images, and mine are in this walker image folder, select all our images in our sequence and then hit OK. Then we get to watch Photoshop do all the hard work of importing every single image of our sequence. In a couple of seconds, you'll see we have a new Photoshop file and every layer in that file is one of the images from our sequence in order according to their file name. So that saved us a lot of time. By default, Photoshop sizes our new image to the same size as the images we imported to create it.

We know that each frame of our animation is 245 pixels by 400. So our sprite will have to be 245 pixels wide as it is now and 4000 pixels high, because we have 10 frames, each of them 400 pixels tall. So we'll change our canvas size to 4000 pixels, and make sure we're anchored at the top. And if we zoom out, you can see what we've just created, and that's basically the start of our sprite image. So yes, this is going to be a very big image, and that's why short animations work best for this kind of technique.

Otherwise, your image could get ridiculously huge and probably bigger than you'd ever want to use on the Internet. We'll be stacking our images one on top of another, kind of like making a filmstrip. So I'm going to create some guides to help make sure I get everything to line up accurately. You can create these guides manually, or if you like shortcuts like me, you can use a Photoshop plug-in called GuideGuide which you can get from guideguide.me. It's one that I like to use because it automates the process of making guides, and that's never a fun thing to do. So back to Photoshop, we'll open our GuideGuide plug-in, and I'll create guides every 400 pixels, since I know our frames are 400 pixels tall.

And if we zoom out, we can see it has created guides for us every 400 pixels, and it took at about a second, and it would have taken me a few minutes. So now we'll arrange each one of our layers in a stack. But I'll move each layer into place using the guides until we have a stack of all our frames on top of each other. Our very last step, once we have all our frames stacked up in order is to export the image we just made for the web. Make sure to save your PSD somewhere, too, so you'll have that source file because it didn't take that long to arrange all these frames, but I don't really want to do it again.

Once you have your file saved, you can export this file for web, and it doesn't need to be transparent. I'm going to make it a PNG file and then just hit Save, and I'll save this with my files. Now that we've saved it for web, our image is ready to be animated. Make a note of the width and height of your image before you close Photoshop. You'll want to have those handy when we start writing the CSS for the animation in the next tutorial.

Show transcript

This video is part of

Image for CSS: Animations
CSS: Animations

29 video lessons · 11779 viewers

Val Head
Author

 
Expand all | Collapse all
  1. 4m 47s
    1. Welcome
      41s
    2. What you should know before watching this course
      58s
    3. Vendor prefixes and browser support
      2m 11s
    4. Using the exercise files
      57s
  2. 28m 16s
    1. Animation basics
      6m 32s
    2. Exploring animation delay and the fill-mode property
      6m 6s
    3. Working with animation direction
      4m 49s
    4. Understanding easing
      8m 47s
    5. Challenge: Adding keyframes to our animation
      49s
    6. Solution: Adding keyframes to our animation
      1m 13s
  3. 47m 37s
    1. Creating a seamlessly looping animation
      6m 27s
    2. Animating an element into place
      5m 43s
    3. Playing and pausing an animation on hover
      6m 20s
    4. Animating 3D transforms
      8m 6s
    5. Preparing a sprite image for animation
      4m 55s
    6. Animating the sprite image with steps
      5m 34s
    7. Chaining multiple animations on one element
      8m 2s
    8. Challenge: Adding a third animation to the chain
      46s
    9. Solution: Adding a third animation to the chain
      1m 44s
  4. 19m 54s
    1. A preview of what we'll be creating
      1m 10s
    2. Setting up the HTML structure
      1m 48s
    3. Adding the header animation
      5m 57s
    4. Animating the data
      6m 8s
    5. Adding interactivity with JavaScript
      4m 51s
  5. 12m 44s
    1. Why and when to use CSS animations
      4m 50s
    2. Organizing animation code for semantics and fallbacks
      4m 51s
    3. Crafting effective animations
      3m 3s
  6. 3m 0s
    1. Helpful online tools for creating and building animations
      3m 0s
  7. 24s
    1. Next steps
      24s

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.

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 CSS: Animations.

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

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.