Solved

Erase part of a movie clip

Posted on 2009-05-03
4
740 Views
Last Modified: 2013-11-11
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?  
0
Comment
Question by:TonoNam
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:davidwestfall
ID: 24290967
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
 

Author Comment

by:TonoNam
ID: 24291239
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
 
LVL 1

Accepted Solution

by:
davidwestfall earned 500 total points
ID: 24291277
Sorry if I was a bit vague, you must click on "PLAY THIS GAME!" first.
0
 

Author Comment

by:TonoNam
ID: 24291855
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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now