login/register

Snip!t from collection of Alan Dix

see all channels for Alan Dix

Snip
summary

Back when video games were still fun (we’re talking ab...
example sprites
As game complexity increased, techniques developed to ma ...
And what does this have to do with the web?
... the associated “before” and “after” link states.

A List Apart: Articles: CSS Sprites: Image Slicing’s Kiss of Death
http://www.alistapart.com/articles/sprites

Categories

/Channels/techie/css

[ go to category ]

/Channels/techie/web development

[ go to category ]

For Snip

loading snip actions ...

For Page

loading url actions ...

Back when video games were still fun (we’re talking about the 8-bit glory days here), graphics were a much simpler matter by necessity. Bitmapped 2-dimensional character data and background scenery was individually drawn, much like today’s resurgent pixel art. Hundreds and later thousands of small graphics called sprites were the building blocks for all things visual in a game.

example sprites

As game complexity increased, techniques developed to manage the multitude of sprites while keeping game play flowing. One variation saw sprites being plugged into a master grid, then later pulled out as needed by code that mapped positions of each individual graphic, and selectively painted them on the screen.

And what does this have to do with the web?

Everything old is new again, and though the rise of 3D games has made sprite maps obsolete, the concurrent rise of mobile devices with 2D gaming capabilities have brought them back into vogue. And now, with a bit of math and a lot of CSS, we’re going to take the basic concept and apply it to the world of web design.

Specifically, we’re going to replace old-school image slicing and dicing (and the necessary JavaScript) with a CSS solution. And because of the way CSS works, we’re going to take it further: by building a grid of images and devising a way to get each individual cell out of the grid, we can store all buttons/navigation items/whatever we wish in a single master image file, along with the associated “before” and “after” link states.

HTML

<p>Back when video games were still fun (we&#x2019;re talking about the 8-bit glory days here), graphics were a much simpler matter by necessity. Bitmapped 2-dimensional character data and background scenery was individually drawn, much like today&#x2019;s resurgent pixel art. Hundreds and later thousands of small graphics called sprites were the building blocks for all things visual in a game.</p> <img src="/d/sprites/sprites.gif" alt="example sprites" style="margin: 10px auto;" height="112" width="175"> <p>As game complexity increased, techniques developed to manage the multitude of sprites while keeping game play flowing. One variation saw sprites being plugged into a master grid, then later pulled out as needed by code that mapped positions of each individual graphic, and selectively painted them on the screen.</p> <h2 id="thewebconnection">And what does this have to do with the web?</h2> <p>Everything old is new again, and though the rise of 3D games has made sprite maps obsolete, the concurrent rise of mobile devices with 2D gaming capabilities have brought them back into vogue. And now, with a bit of math and a lot of CSS, we&#x2019;re going to take the basic concept and apply it to the world of web design.</p> <p>Specifically, we&#x2019;re going to replace old-school image slicing and dicing (and the necessary JavaScript) with a CSS solution. And because of the way CSS works, we&#x2019;re going to take it further: by building a grid of images and devising a way to get each individual cell out of the grid, we can store all buttons/navigation items/whatever we wish in a single master image file, along with the associated &#x201c;before&#x201d; and &#x201c;after&#x201d; link states.</p>