8bitrocket Diatribe – Dynamic Sprite Sheets and What’s on Jeff’s DVR

I have been working on a few new projects that require speed and blit operations. This has given me the opportunity t to research and re-fine my methods. At one time I used arrays of bitmapData objects, pre-cached from movieClips. Those were especially needed when I was working with designers who were not savvy with tile sheets. The array is fast and efficient, but it uses a lot of memory and is redundant when you also have a sprite sheet in memory. Also, since arrays are passed by reference, I ran into some problems accidentally writing over the original array of data when I wanted to run matrix transformations in-line while the games were running. Sometimes I would corrupt the original sprite data and I couldn’t figure out why. So, after quite a while using arrays, I switched to mostly blitting directly from sprite sheets to the canvas. The sprite sheet pngs acted pretty much like arrays, the only draw back being that I had to do all of the work to pre-render my rotations, scale and other transformations in Fireworks and then bring them into Flash manually.

Last week I started really working hard (in my limited time) on a new game, and so I created a tutorial on basic rotation with blitting and some sprite sheets. In it, I use the standard technique described above: I pre-rendered a rotation set of sprites, brought them into Flash as A PNG file and then simulated a sprite rotation by running through them in order.

Since I am trying to get my games done in under 24 hours (not in a row), I wasted far too much time creating the 36 rotations above. It probably took me about 30-40 minutes to do a separate sprite sheet for each rotation of 36 angles for 2 different flipping cells. That was just too much time. Once the sheet is complete, it is very easy to blit from, but it just takes far too much time to do up front. So, I decided to combine the idea of an pre-cached array of tiles – (rotate the sprite in a movieClip and draw each frame into a BitmapData object that is then pushed into an array) with the idea of a sprite sheet in pure BitmapData. That would necessitate me using the same techniques of pre-caching a MC, but instead of pushing the resulting BitmapData into an array, it would be pushed into another BitmapData object as a long strip of 36×36 cells. That way I would be able directly from the sprite sheet, but not have to waste 45 minutes in Fireworks to make it happen.

A funny thing happened when I tried to do it though. I was able to create the dynamic sheet, but it took much longer to figure out an efficient method than I thought. I first tried to just instantiate 36×36 png in the library as a BitmapData, drop that inside a holder MovieClip, rotate that clip and draw the resulting pixels into a BitmapData object. No doing. It did work. The pixels came out with no rotation. Hmm, I think I read that the draw doesn’t work without a Matrix if you want to deform the original BitmapData. Ok, fine, I tried a few more variations, but still did not come up with anything better than the version I wrote back in January for my tutorial on an optimized Asteroids game.

So now I am back to needing both a 36×36 png in the library AND a movieClip holder for that PNG. the PNG must be at -18, -18 to rotate it on its axis. When I create the holder clip in Flash it needs to be set at 18,.18 to compensate for the fact that BitmapData knows nothing about the – portion of of the screen in either x or y directions.

Here is the code I am currently using. It works fine, but I want to take away on of the MovieClips. In any case, it is easier than creating all of them up front in a paint tool:

    function createPlaneSheets():void {
        var holder:MovieClip=new MovieClip();
        var plane1Holder:plane1holder=new plane1holder();

        var spriteMapBitmap:BitmapData=new BitmapData(36,36,true,0x00000000);
        spriteMapBitmap.draw(holder,new Matrix());

        var test:Bitmap=new Bitmap(spriteMapBitmap);

        var holder2:MovieClip=new MovieClip;

        var insideHolder:MovieClip=new MovieClip();
        var plane1:BitmapData=new plane1bitmap(36,36);
        var bitmapHolder:Bitmap=new Bitmap(plane1);

        var spriteMapBitmap2:BitmapData=new BitmapData(36,36,true,0x00000000);
        spriteMapBitmap2.draw(holder2,new Matrix());

        var test2:Bitmap=new Bitmap(spriteMapBitmap2);



The first version is my tried and true older code and it works fine. the holder is a MC and it contains and instance of an MC in the library. The library MC has the 36×36 sprite at -18, -18. The library MC is instantiated as Plane1Holder and set at 18,18 to compensate for the -18.-18 offset used for rotation. I then rotate the plane1Holder 45 degrees and draw it into the spriteMapBitmap BitmapData object. I place that inside a Bitmap called test and display them on the screen. Both test and Holder show a plane at 45 degrees.

BUT the code under that is SUPPOSED to make it easier by eliminating the need for the MC in the library and instantiating the Plane1 PNG as a BitmapData object directly from the library. I then add it to a Bitmap object called bitmapHolder. I add bitmapHolder to an MC that can be rotated and put all of that inside the holder2 MC. I rotate insideHolder to 90 degrees and then draw its contents directly into a spritemapBitmap2 Bitmapdata object.

When I try to display both of those on the screen I get Holder2, but NOTHING in test2.

Anyway, this is really frustrating and I’ll have to play with it more before I use it in a game or a tutorial. Below is my example. It uses the plane sprite from my new game.


As you can see, the 4th sprite at 200, 200 just doesn’t show up. Anyway, with a new baby in the house, all of my work time is between 12:00AM and 2:00AM, so I will get back to it tonight and see what I can figure out. I’ll have a new method of blitting from a Dynamic Sprite Sheet soon and a Tutorial on it too.


What’s On Jeff’s DVR?
I live in the USA and have the single greatest TV service available, Dish Network. They were the first to have the 30 second commercial Skip button on their DVR (and never got rid of it like other services), their DVR holds 200 hours of standard and 50 hours of HD programming, and they let me hook a hard drive up to my system to store movies and shows! Take that NINTENDO! I get all of the channels because I am a TV and Soccer junkie I DVR is filled with stuff all the time. Anyway, I’m sure all of you have your own favorite shows and things your DVR every day. Here is of the things on my DVR list. What does your list look like?

In no particular order:

1. The Shield, FX Network, Tuesday Nights: The first episode of the final season aired yesterday.
2. Numbers, CBS, Friday Nights. I’d like to DVR the show with Jennifer Love Hewitt’s giant rack that’s on before-hand, but the show sucks and my wife would figure it was just to see her boobies…which it would be.
3. The Office, NBC, Thursdays. I loved the British version, and USA one has a cache all its own.
4. My Name is Earl, NBC Thursdays
5. 30 Rock, NBC, Thursdays – Funniest show on TV.
6. The Simpsons, Fox, Sunday
7. King Of The Hill, Fox, Sunday
8. The Daily Show, Comedy Central, Mon-Thurs
9. The Colbert Report, Comedy Central, Mon-Thurs
10. Late Nite with David Letterman, CBS, Mon-Friday
11. The Late Show With Conan O’Brien, NBC, Mon-Friday
12. Talk Soup, E, Friday
13. The Best Week Ever, VH1, Friday
14. Heroes, NBC, Monday
15. Chuck, NBC, Monday
16. How I met Your Mother, CBS, Monday
17. 24 (when ever the fuck they put it back on). Fox.
18. Life – NBC – Now on Friday. best show on TV.
19. Saturday Night Live, NBC, Saturday.
20. Any USA National team Soccer Game
21. Any Galaxy Soccer Game.
22. Thursday night MLS game on ESPN2 in HD
23. The EPL on Fox Soccer Channel Saturday, Sunday and sometimes Monday – Teams I DVR-Fulham, Blackburn, West Ham, Arsenal, Chelsea, MUCF and MCFC.
24. Psych, USA Network, Friday.
25. Generation Kill (now over) Sundays, HBO.
26. Californication, Showtime, Wednesday
27. The Terminator, The Sarah Connor Chronicles, Fox, Monday
28 (Upcoming) Fringe, Fox, Tuesday
29. House, Fox, Tuesday.
30. Reaper, The CW, (When ever they decide to put it back on).
31. It’s always Sunny In Philadelphia, FX, (whenever they decide to put it back on)
32. Entourage, HBO, Sunday – It starts up again this week.

There are also loads of kids shows and some shows on there, and a bunch of home shows that my wife watches. Also, unlisted are shows that I I wish I had time to watch like Pushing Daises. etc. I have to watch most of these in the wee hours of the morning as it is. So, what cool shows am I not watching? What would you recommend?

Leave a Reply