//------------------------------------------------// 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;
//Set up the sprites container=new Sprite(); stage.addChild(container); playField=new Sprite(); container.addChild(playField);
//--------------------------------------------------------------------------------------- private function mainloop(e:Event):void{ moveBob(); copyBitmap(); }
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{ container.addChild(this["bmData"+currentBitmapNumber]); this["bm"+currentBitmapNumber].draw(playField); if(++currentBitmapNumber==4){ currentBitmapNumber=1; } }
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.
Squize.
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are our personal opinions and do not represent our customer's view in anyway.
© Copyright 2009, gaming your way
E-mail