A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [AS8] make hole

  1. #1
    Member
    Join Date
    Oct 2008
    Posts
    49

    [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.

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    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!

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    I guess you have to better explain your scenario- is it like worms 1

    or what?

  4. #4
    Member
    Join Date
    Oct 2008
    Posts
    49
    Actionscript 2, typo..

    render: yes just like that

  5. #5
    Senior Member hatu's Avatar
    Join Date
    Jan 2007
    Posts
    480
    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.
    http://hatu.biz
    Portfolio & games

  6. #6
    Member
    Join Date
    Oct 2008
    Posts
    49
    Quote 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.

  7. #7
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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 * (radius); 
    but since you need only to cover 1/4 th it should be:
    PHP Code:
    var steps = (PI * (radius)) / 4
    after that use
    PHP Code:
    fillRect(rect:Rectanglecolor:uint):void 
    to draw the rectangles with the key color

    just in case- bitmapData operations:
    http://livedocs.adobe.com/flash/9.0/...itmapData.html

  8. #8
    Member
    Join Date
    Oct 2008
    Posts
    49
    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?

  9. #9
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    711
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center