Erase part of a movie clip

How can I erase part of a movie clip once that an event happens? For example lets say I have a movie clip called bullet_mc and another movie clip called wall_mc.  The movie clip bullet_mc moves to the right until it hits wall_mc. Is there a way to erase part of wall_mc instead of creating a white circle? Or should the wall_mc should be a shape instead of a movie clip?  
TonoNamAsked:
Who is Participating?
 
davidwestfallConnect With a Mentor Commented:
Sorry if I was a bit vague, you must click on "PLAY THIS GAME!" first.
0
 
davidwestfallCommented:
Look at http://www.newgrounds.com/portal/view/344206  There is a tutorial on destructible terrain under Advanced -> Destructible Terrain (Worms).  You might also try googling destructible terrain.
0
 
TonoNamAuthor Commented:
I already looked at: http://www.newgrounds.com/portal/view/344206  and I could not find the advanced tab. Navigating throuout the page I found this though:
http://artbit.deviantart.com/art/Destructible-Terrain-Engine-39769589
How could I create something like that?
0
 
TonoNamAuthor Commented:
I already watched the tutorial and tried to follow all the instructions for some reason when I run the code it does not play. it displays so many errors. The link you gave me was very helpful I dont understand what am I doing wrong. so far I created an .AS file with the following code (see code snippet): I also created a .fla flie with the same name as the .AS file and also located in the same directory. Moreover I pulished all all the move clips to the class DT (thats the name of the .as and .fla files). I also tried pasting the code that the tutorial gave us in just the first frame of the .fla file without creating the .as file. I guess the author of this tutorial ment to create the .as file because of his firs line of code had: import flash........

I know I should prob know now how to do this with the link you gave me its just that I am new to action scrip. I apresiate your help so far and I wish I had acceped the last answere as a solution. If it is posible could you send me a .fla file and an .as file by mail to antonio@namnum.com of this tutorial. If it is not posible then I guess you guys prob have rules on this matter and I def understand.


the code that the tutorial has is: (and the instuctions are attached)

import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
//imports the nessacary classes
var max:Number = 400;
// sets a variable which aids in duplicating movieclips
var myMatrix:Matrix = new Matrix();
// creates a matrix. matrices are used to translate, rotate, skew, and scale things
// using AS. Matrices are important in this script because they allow the blendMode
// attribute of the draw() function to be activated, so to speak. Otherwise, they
// serve no purpose in this script.
var myCT:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
// changes the ratios of the colors in RGB. The 1's represent the amount the current
// RGBA is being multiplied by, so it stays the same, and the 0's are the offsets, or
// the amount being added to each RGBA value, so it stays the same. In this script
// the ColorTransform serves the same purpose as the Matrix, however if you really
// wanted to you could switch the colors around.
var myBmp:BitmapData = new BitmapData(1000, 1000, true, 0x00000000);
// creates a bitmap 1000 pixels X 1000 pixels
attachBitmap(myBmp, 0, "never", false);
// attaches the bitmap to the stage
attachMovie("hole", "hole_mc", 10);
hole_mc._visible = false;
// attaches the hole movie clip to the stage and makes it invisible
myMatrix.translate(0, 120);
// defines the created matrix. In this case, the matrix is going to translate the
// map 120 pixels down
attachMovie("square", "square_mc", 11);
// attaches the square movieclip to the stage
function makeMap(x) {
attachMovie("map"+x, "map"+x, 5);
myBmp.draw("map"+x, myMatrix, myCT, "layer");
removeMovieClip("map"+x);
}
// creates a function that will build a map. it attaches a map in the library, then
// draws the map to a bitmap, and then erases the original mc, leaving the bitmap
// behind with an image of the map drawn on it. This allows the map to be edited as
// a bitmap and therefore having destructable terrain.
onMouseDown = function () {
duplicateMovieClip(square_mc, "square"+max, max);
max++;
};
onEnterFrame = function () {
square_mc._x = _xmouse;
square_mc._y = _ymouse;
square_mc._visible = false;
if (max>400) {
max = 300;
}
for (i in _root) {
// sets a variable i in the scope of _root. basicaly this checks everything
// root.
if (_root[i]._name.indexOf("square") != -1) {
// checks if the name of something in _root. starts with square, in this
// case the duped square mc.
_root[i]._y += 20;
// adds 20 pixels to the square to make it fall.
if (_root[i]._name != "square_mc") {
// if the mc is not the original
if (myBmp.getPixel(_root[i]._x, _root[i]._y) != 0) {
// checks the color value of the x,y coordinates of the duped
// square. If the coordinates are outside of the bitmap, it
// returns 0, otherwise returns a number. if the function
// returns a number then the square hit the bitmap
var myMatrix:Matrix = new Matrix();
myMatrix.translate(_root[i]._x, _root[i]._y);
// creates a matrix that will translate the hole movie clip
// to the x,y coordinates of the duped square
myBmp.draw(hole_mc, myMatrix, myCT, "erase");
// uses the draw function to draw the image of the hole over
// the bitmap. the 2nd and 3rd attributes move the hole
// to the square and adjust the color. The 4th attribute is
// the blend mode. what this does is change the way the hole
// is drawn over the map. The erase means that the bitmap is
// getting erased where the hole touches it. This is the
// most important part of destructable terrain. other
// blendModes are: invert-inverts the color, layer- layers the
// two objects, darken-creates a semi-see-thru effect, and a
// lot more. Erase is the only blendMode that will work for
// destructable terrain because all the other ones just change
// colors instead of removing pixels.
_root[i].removeMovieClip();
// removes the square. duh
}
}
}
}
};
makeMap(0);
// uses the created function to attach the map to the bitmap.








package {
 
	import flash.display.BitmapData;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
 
 
 
	public class DT extends MovieClip {
 
		public function DT() {
 
			//imports the nessacary classes
			var max:Number=400;
			// sets a variable which aids in duplicating movieclips
			var myMatrix:Matrix = new Matrix();
			// creates a matrix. matrices are used to translate, rotate, skew, and scale things 
			// using AS. Matrices are important in this script because they allow the blendMode
			// attribute of the draw() function to be activated, so to speak. Otherwise, they 
			// serve no purpose in this script.
			trace("hello");
			var myCT:ColorTransform=new ColorTransform(1,1,1,1,0,0,0,0);
			// changes the ratios of the colors in RGB. The 1's represent the amount the current
			// RGBA is being multiplied by, so it stays the same, and the 0's are the offsets, or
			// the amount being added to each RGBA value, so it stays the same. In this script
			// the ColorTransform serves the same purpose as the Matrix, however if you really
			// wanted to you could switch the colors around.
			var myBmp:BitmapData=new BitmapData(1000,1000,true,0x00000000);
			// creates a bitmap 1000 pixels X 1000 pixels
			attachBitmap(myBmp, 0, "never", false);
			// attaches the bitmap to the stage
			attachMovie("hole", "hole_mc", 10);
			hole_mc._visible=false;
			// attaches the hole movie clip to the stage and makes it invisible
			myMatrix.translate(0, 120);
			// defines the created matrix. In this case, the matrix is going to translate the 
			// map 120 pixels down
			attachMovie("square", "square_mc", 11);
			// attaches the square movieclip to the stage
			function makeMap(x) {
				attachMovie("map"+x, "map"+x, 5);
				myBmp.draw("map"+x, myMatrix, myCT, "layer");
				removeMovieClip("map"+x);
			}
			// creates a function that will build a map. it attaches a map in the library, then
			// draws the map to a bitmap, and then erases the original mc, leaving the bitmap 
			// behind with an image of the map drawn on it. This allows the map to be edited as
			// a bitmap and therefore having destructable terrain.
			onMouseDown = function () {
			duplicateMovieClip(square_mc, "square"+max, max);
			max++;
			};
			onEnterFrame = function () {
			square_mc._x = _xmouse;
			square_mc._y = _ymouse;
			square_mc._visible = false;
			if (max>400) {
			max = 300;
			}
			or (i in _root) {
			// sets a variable i in the scope of _root. basicaly this checks everything 
			// root.
			if (_root[i]._name.indexOf("square") != -1) {
			// checks if the name of something in _root. starts with square, in this
			// case the duped square mc.
			_root[i]._y += 20;
			// adds 20 pixels to the square to make it fall.
			if (_root[i]._name != "square_mc") {
			// if the mc is not the original 
			if (myBmp.getPixel(_root[i]._x, _root[i]._y) != 0) {
			// checks the color value of the x,y coordinates of the duped 
			// square. If the coordinates are outside of the bitmap, it 
			// returns 0, otherwise returns a number. if the function 
			// returns a number then the square hit the bitmap
			var myMatrix:Matrix = new Matrix();
			myMatrix.translate(_root[i]._x, _root[i]._y);
			// creates a matrix that will translate the hole movie clip
			// to the x,y coordinates of the duped square
			myBmp.draw(hole_mc, myMatrix, myCT, "erase");
			// uses the draw function to draw the image of the hole over
			// the bitmap. the 2nd and 3rd attributes move the hole
			// to the square and adjust the color. The 4th attribute is 
			// the blend mode. what this does is change the way the hole
			// is drawn over the map. The erase means that the bitmap is
			// getting erased where the hole touches it. This is the 
			// most important part of destructable terrain. other 
			// blendModes are: invert-inverts the color, layer- layers the 
			// two objects, darken-creates a semi-see-thru effect, and a 
			// lot more. Erase is the only blendMode that will work for
			// destructable terrain because all the other ones just change
			// colors instead of removing pixels. 
			
			_root[i].removeMovieClip();
			// removes the square. duh
			}
			}
			}
			};
		}
 
		makeMap(0);
		// uses the created function to attach the map to the bitmap.
 
 
 
 
	}
 
 
}

Open in new window

Capture.JPG
0
All Courses

From novice to tech pro — start learning today.