-
[AS2] make hole
Is it possible to make a hole in a movieclip? not just paint a circle, but removing a circle. To make hittest work properly..
Last edited by M4R7IN; 01-18-2009 at 01:48 PM.
-
Senior Member
Wow, someone from the future!!! How's AS8.0 workin' for ya?
Nah, just kidding.
I don't really know what you mean my making a hole, but, if you make an inverted circle movieClip (lets say a big rectangle with a hole in the middle, and call it "mask_mc"), and then attach it to the movieclip you wanted a circle in, then use my_mc.setMask(mask_mc). I'm not too sure about it working on hitTests, but it will make a hole in the mc!
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
I guess you have to better explain your scenario- is it like worms 1
or what?
-
Actionscript 2, typo..
render: yes just like that
-
Senior Member
If you have your foreground like on Worms there as a bitmap then you can use getPixel32() for hittest by comparing the alpha. And draw circles on it that have an alpha of 0%(?) I'm not actually sure if that erases the pixels from it's place, but it's worth a try.
-
Originally Posted by hatu
If you have your foreground like on Worms there as a bitmap then you can use getPixel32() for hittest by comparing the alpha. And draw circles on it that have an alpha of 0%(?) I'm not actually sure if that erases the pixels from it's place, but it's worth a try.
Is there any easy way to paint a circle with code?
edit: i found this function:
Code:
MovieClip.prototype.drawCircle = function(r:Number, x:Number, y:Number, bgColor:Color){
this.beginFill(bgColor, 100);
this.moveTo(x+r, y);
var A:Number = Math.tan(22.5 * Math.PI/180);
for (var angle:Number = 45; angle<=360; angle += 45) {
var endx:Number = r*Math.cos(angle*Math.PI/180);
var endy:Number = r*Math.sin(angle*Math.PI/180);
var cx:Number = endx+r*A*Math.cos((angle-90)*Math.PI/180);
var cy:Number = endy+r*A*Math.sin((angle-90)*Math.PI/180);
this.curveTo(cx+x, cy+y, endx+x, endy+y);
}
}
it works, but the only problem is that it paints behind the shape in the movieclip if i use "movieclip.drawCircle(X,X,X,X)"...
Last edited by M4R7IN; 02-03-2009 at 03:50 PM.
-
you can draw multiple rectangles (very fast) to create 1 circle like this:
just concentrate on one quarter but render the boxes centered within the circle so that its corners will hit the imaginative circle border.
You may ask how many iterations you need? - I would make it dependable from the outline size which is
PHP Code:
PI * (2 * radius);
but since you need only to cover 1/4 th it should be:
PHP Code:
var steps = (PI * (2 * radius)) / 4;
after that use
PHP Code:
fillRect(rect:Rectangle, color:uint):void
to draw the rectangles with the key color
just in case- bitmapData operations:
http://livedocs.adobe.com/flash/9.0/...itmapData.html
-
nice render ill use the function in my previous post though, maybe you know why it doesnt paint over the existing shape in my movieclip?
-
Senior Member
You can have a look at this super fast library, it's AS3, but should be OK for AS2 with a few modifs : http://www.bytearray.org/?p=67
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|