Destructible terrain scrolling
Hi,
Just wondering if anybody has any pointers for getting the destructible terrain to scroll as in micro warriors (http://www.birchlabs.co.uk/Micro%20Warriors.swf). As soon as I move the terrain the holes no longer appear in the right places.
Sebastian
destructible terrain code
Hi. To make this work you need three movieclips: dot, ground and hole. Pretty straightforward, but as soon as I use my scrolling function things get screwed up. The scrolling function is below as well. Thanks so much for the help!!
//the code
import flash.display.BitmapData;
import flash.geom.*
gravity=3
var myCT:ColorTransform = new ColorTransform (1, 1, 1, 1, 0, 0, 0, 0);
var my_mc:MovieClip = this.createEmptyMovieClip ("mc", 1);
var myBmp:BitmapData = new BitmapData (Stage.width, Stage.height, true, 0x00000000);
//levelBitmap.draw(ground, m);
myBmp.draw (ground, myMatrix);
my_mc.attachBitmap (myBmp, 0, "never", false);
this.attachMovie ("hole", "hole_mc", 2);
this.attachMovie ("ground", "ground", 3);
this.attachMovie ("dot", "dot", 4);
dot._x=200
hole_mc._x = -100;
//make first hole
var myMatrix:Matrix = new Matrix ();
myMatrix.translate(ground._x, ground._y)
myBmp.draw(ground, myMatrix);
ground.swapDepths(_root.getNextHighestDepth());
removeMovieClip(ground);
onMouseDown = function () {
var myMatrix:Matrix = new Matrix ();
myMatrix.translate (this._xmouse - hole_mc._width / 2, this._ymouse - hole_mc._height / 2);
myBmp.draw (hole_mc, myMatrix, myCT, "erase");
};
onEnterFrame = function () {
//get the pixels
if (myBmp.getPixel (dot._x, dot._y + 1) == 0) {
dot._y+=gravity;
}
};
//and the scrolling function
function scrollControll(ob){
ob._x += (((Stage.width/2)-scrollAdjustHorizontal/3.5-center._x)/10)*friction;
ob._y += (((Stage.height/2)-scrollAdjustVertical/3.5-center._y)/10)*friction;
}
scrollAdjustHorizontal = DistanceBetweenHorizontal(center, crosshair_mc);
//the center would be the player's character and crosshair_mc is just set to the mouse position. DistanceBetweenHorizontal + vertical just calculates the distance obviously.
function DistanceBetweenHorizontal(mc1, mc2){
var dx = mc2._x - mc1._x;
return(dx);
}
function DistanceBetweenVertical(mc1, mc2){
var dy = mc2._y - mc1._y;
return(dy);
}