# A runtime spritesheet packer. Converts external swfs to blittable bitmaps

**URL:** <https://forum.kirupa.com/t/a-runtime-spritesheet-packer-converts-external-swfs-to-blittable-bitmaps/325783>\
**Category:** open source\
**Created:** [November 4, 2011, 5:52am UTC](https://forum.kirupa.com/t/a-runtime-spritesheet-packer-converts-external-swfs-to-blittable-bitmaps/325783 "2011-11-04T05:52:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlLydon](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@CarlLydon](https://forum.kirupa.com/u/CarlLydon)\
**Post date:** [November 4, 2011, 5:52am UTC](https://forum.kirupa.com/t/a-runtime-spritesheet-packer-converts-external-swfs-to-blittable-bitmaps/325783/1 "2011-11-04T05:52:46Z")

</div>

[COLOR=#232323]Hi guys. this is my first upload; I hope someone finds it useful. Maybe there’s another solution on Kirupa like this, but I thought I’d upload it in case there isn’t one.[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]Recently I started a game you can find here:[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323][http://carllydon.com/games/smart2/[/COLOR]](http://carllydon.com/games/smart2/%5B/COLOR%5D)  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]So far it runs smoothly at 60 fps with hundreds of enemies and particles. I accomplished this through “blitting” which is not using the Flash sprite engine at all in favor of using bitmapData copy/paste routines to handle all the map scrolling effects and moving graphics around.[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]I wanted to keep the small file size of vector objects, and the ability to import in only the swf animations I needed for a given game level. So, I made a spritesheet packer.[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]I’ve included a demo that shows how to use the code. What it does:[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]1. The document class instantiates a movieclip[/COLOR]  
[COLOR=#232323]2. The mc has the “spriteSheetMaker.as” attached to it[/COLOR]  
[COLOR=#232323]3. The doc class tells “spriteSheetMaker.as” (SSM) what swf to load[/COLOR]  
[COLOR=#232323]4. SSM loads the swf[/COLOR]  
[COLOR=#232323]5. When done SSM examines the width, height and number of frames in the animation.[/COLOR]  
[COLOR=#232323]6. SSM iterates through all the frames in the animation and converts to bitmap[/COLOR]  
[COLOR=#232323]7. Each bitmap is added to an array for that game object.[/COLOR]  
[COLOR=#232323]8. Each sheet array is added to an object “pSriteSheets” and given a property name so it’s findable by name.[/COLOR]  
[COLOR=#232323]9. When all this is done, displaySpriteSheet() is run (this is just for the demo)[/COLOR]  
[COLOR=#232323]10 displaySpriteSheet() retrieves each bitmap and places it on the stage[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]I also included an example “laserGreen.as” which shows how the bitmaps can be used during a game.[/COLOR]  
[COLOR=#232323]Basically, it works like this:[/COLOR]  
[COLOR=#232323]  
[/COLOR]  
[COLOR=#232323]1. Each game object is has a string indicating the name of the spritesheet it uses[/COLOR]  
[COLOR=#232323]2. The game object can retrieve by name the entire sheet array from the pSriteSheets object in document class (pSriteSheets[vName];)[/COLOR]  
[COLOR=#232323]3. Once you have the sheet array, you can grab any bitmap from the array along with the width heigh etc. and then proceed with blitting.[/COLOR]
