I'm having trouble with the BlitMask "wrap" feature in a game Im working on.
Basically, the game is a car on a scrolling landscape, with obstacles to avoid hitting using the UP and DOWN arrow keys; the "road" is actually an empty strip in the scrolling landscape)
http://www.byrographics.com/flash/drivingGame/
Once the scrolling MovieClip (the landscape) has reached the end of the first loop (scrolled on the x-axis to the actual length of the horizontal panel being scrolled; about 6000 pixels), my hitTest function completely stops working.
The masking, wrapping and runtime performance continue to function perfectly. Just the hitTest fails.
Thanks
Here's the code for the BlitMask:
lsm = new BlitMask(landscape,0,0,stage.stageWidth,stage.stageHeight,true,true,0,true);
lsm.enableBitmapMode();
Here's the bitmapData code for the hitTest:
var carRect:Rectangle = car.getBounds(this);
var carBmpData = new BitmapData(carRect.width,carRect.height,true,0);
carBmpData.draw(car);
var landscapeRect:Rectangle = landscape.getBounds(this);
var landscapeBmpData = new BitmapData(landscapeRect.width,landscapeRect.height,true,0);
landscapeBmpData.draw(landscape);
Here's the scrolling function (enter frame loop) that contains the hitTest:
function scrollPanel(e:Event):void
{
if (up)
{
car.y -= speed;
}
if (down)
{
car.y += speed;
}
if (carBmpData.hitTest(new Point(car.x,car.y),255,landscapeBmpData,new Point(landscape.x,landscape.y),255))
{
gamestarted = false;
timer.stop();
stage.removeEventListener(Event.ENTER_FRAME, scrollPanel);
controls.txt.text = "You Crashed!";
car.gotoAndStop(2);
TweenMax.to(car, 1, {scaleX:10, scaleY:10, alpha:0, ease:Quad.easeOut});
if (highscore < score)
{
highscore = score;
controls.highScoreText.text = "High Score: " + highscore.toString();
}
score = 0;
}
else
{
controls.txt.text = "Drive Safely!";
landscape.x -= speed * 4;
lsm.update(null, true);
}
}