I'll write something up later for this.
Basically, I find it impractical to create truly large scrolling panels on the stage in flash pro. So I create the panel by looping through all of the frames of a single 600x400 MovieClip in the library. Each frame is only 600x400, so it's easy to work with on the stage, and the final result after AS3 manipulation is 6000 pixels wide(!)
Long story short: each frame of the movieclip is a tile-able section of the 6000 pixel panel, including the static objects in the road.
The road itself is simply a "hole" in the movieclip; the road you see in the game is actually a background shape that shows through the hole.
I create an instance of each frame of this movieclip in a for loop and add it to the width of a Sprite. 2ms later I have the full-size panel!
ActionScript Code:
var temp:Section = new Sections();
var num:int = temp.totalFrames;
var panel:Sprite = new Sprite();
for(var i:int = 0; i < temp.totalFrames; i++)
{
var mc:Sections = new Sections();
mc.gotoAndStop(i+1);// if i = 0, this would be frame1
mc.x = panel.width;// this butts the sections end to end in the panel
panel.addChild(mc);
}
temp = null; // get rid of the temp file I used to get the totalFrames
I then assigned a
BlitMask to the panel, which converts the whole thing into one large bitmap with a 600x400 mask.
(including the static objects in the road)
The content of the bitmap outside the BlitMask is totally invisible to Flash Player and is not rendered, and does not contribute to performance overhead. (performance delta is purportedly on the order of 1000% improvement, compared to a traditional mask)
ActionScript Code:
// create an instance of the blitmask;
// params: target,x,y,width,height,smoothing,autoupdate,colorfill,wrap
// the "wrap" parameter automatically creates infinite copies of the panel in all directions.
var bm:BlitMask = new BlitMask(panel,0,0,stage.stageWidth,stage.stageHeight,true,true,0,true);
bm.enableBitmapMode();// improves performance.
addChild(panel);
I then create bitmapData instances from the panel and car MovieClips, then compare that pixel data in the HitTest. This resolves the problem of invisible rectangular bounding boxes for irregular objects returning false hits.
I wrap this process in a function.
ActionScript Code:
function createBitmapData():void
{
carRect = car.getBounds(this);
carBmpData = new BitmapData(carRect.width,carRect.height,true,0);
carBmpData.draw(car);
panelRect = panel.getBounds(this);
panelBmpData = new BitmapData(panelRect.width,panelRect.height,true,0);
panelBmpData.draw(panel);
}
The last part is the hitTest in the enter frame loop
ActionScript Code:
if (carBmpData.hitTest(new Point(car.x,car.y),255,panelBmpData,new Point(panel.x,panel.y),255))
{
// if the hitTest returns true (car hit an opaque pixel in the panel), do something, such as display "You've Crashed!" text, stop the panel, explode the car, etc... game over.
}
else
{
// enter frame loop continues to run... panel scrolls, etc...
}
Obviously there's a ton of code missing here, mostly for adding objects to the stage, tweening assets on and off the stage, and some simple logic for the score board.