Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.