Gaming Your Way

May contain nuts.

Infinite bobs

Here's another really old trick we used in 651.


Way back in Amigaland software sprites ( ie, sprites which were plotted by the blitter as opposed to being hardware based, like a mouse pointer ) were called "Bobs" ( Blitter OBjects ). As with everything you could only ever run a certain amount before you started running out of cpu time, so when the first infinite bob effects started appearing in demos every one passed a little bit of involuntary wee.

// Bob properties
        private var ball:Sprite;
        private var bm1:BitmapData;
        private var bm2:BitmapData;
        private var bm3:BitmapData;
        private var bmData1:Bitmap;
        private var bmData2:Bitmap;
        private var bmData3:Bitmap;

        private var currentBitmapNumber:int;

Just set up 3 bitmaps, and then...

//Set up the sprites
            container=new Sprite();
            playField=new Sprite();

Create a holder sprite + add it to the stage, and then a further sprite within that. Also add your bob to the playField ( Not the container or the stage )

Next up, our mainloop,

        private function mainloop(e:Event):void{

moveBob() is however you want to move the bob around the screen, use your nice sin based movement that you've got tucked away. All it's doing is just moving one bob ( ball:Sprite in this case ) around the screen.

The funky bit is the copyBitmap() method,


        private function copyBitmap():void{


It just simply loops through all our bitmaps, copying what's in our playField ( ie the ball ) to the next bitmap. Just written down like this it's a bit tricky to grasp, think of it like an old flick book. You move the bob, you take a copy of the whole screen and store that in a bitmap and then display that, you then move the bob again, and take another grab of it and so on. We use 3 bitmaps because the image will be slightly different on all of them, creating the sense of movement ( Otherwise it wouldn't animate and would just look like a trail behind the bob ).

I can recommend giving it a quick play, it'll take 5 mins to set yourself up with a working example and once it's running infront of you it'll click into place how it actually does work.



Comments (4) -

  • Jeff Fulton

    10/23/2008 4:07:48 PM |

    Cool Zarjazz, Squize! I see you have a lot of Amiga style demos this week. Nice stuff.

  • Squize

    10/26/2008 1:24:28 PM |

    Thanks mate

    ( Although that example swf was I think my first ever bit of as3, there's only so much time for eye-candy :) )

  • John Cotterell

    10/29/2008 7:35:36 PM |

    Nice work, I always wondered how that was done.

  • Squize

    10/30/2008 12:46:11 AM |

    I'm just glad what I wrote made some kind of sense, it's a tricky one to explain.

    Failing that, just decompile the example :)

    I guess I should get on with explaining some other parts of the demo, I've just not been very wordy this week.

Comments are closed